467,926 Members | 1,492 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,926 developers. It's quick & easy.

Which loads faster?

Hi everyone, quick question:

When I first started my website three months ago, I was a total rookie. I used a lot of <img> tags to create borders around things and to dress up different tables on my site.

Later on, I set classes in a CSS external file and used the background-image: command to fill those same tables with the same images.

So my question is: which is faster? I would think the CSS method. And how much faster is it? Fast enough that I should go back through my entire site and change those <img> tags to style sheet references?

Thanks for the help!
Jan 9 '08 #1
  • viewed: 1594
3 Replies
The main time in loading an image is in connecting to the server and downloading the image. All methods are going to require that, so there is no real gain in speed.

The proper way to decide which way to do it, is to use img tags for images that are part of your content. (A picture that you are talking about in the text, or some other element that would be important to content of the page.) If the image is used only for decorating a page, you should use the background-image attribute.
Jan 9 '08 #2
Expert 4TB
No, the css method is quicker. I don't have time to explain it all but it has to do with caching of the external css file compared to the html having to find out if the image is old or not. Each image has to be checked in html but in css the whole css file is checked for age. If it's OK then the images are not checked.

Actually, I need to correct that because it's not true for the initial load. In that case, it doesn't matter.

I promised myself I would stay away for two weeks. ;)
Jan 9 '08 #3

If you remove IMG tags and replace them with a css rule that applies in multiple places, your html code will decrease in size by n X <img> tags and css increases by 1 css declaration.

So good for markup weight as well.
Jan 12 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Sunil Varma | last post: by
4 posts views Thread by Sonnich | last post: by
11 posts views Thread by Mahdi | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.