I'm loading the background of my site using CSS and when I visit my site, it always seems to load the background last. Is there anyway I can get it to load first?
Am I missing something?
Thanks!
| SitePoint Sponsor |
I'm loading the background of my site using CSS and when I visit my site, it always seems to load the background last. Is there anyway I can get it to load first?
Am I missing something?
Thanks!





Hi
I don't think that you can actually tell the browser which part of your pages you want to load first using CSS. Neither can you load one part faster than the others. What you can do is force the browser to load all the images before displaying anything to the user. That way, all the images will appear at the same time.
Javascript would be a much more appropriate tool to handle this as far as I can see.
However, it seems that there is a little trick to do what you want. Put that between your head tags:
Code:<script type="text/javascript"> load_img = new Image(); load_img.src = 'image file name here'; </script>
Will having that javascript in my page still allow me to meet W3C validation? Also... off the wall question.... but I've heard that javascript can mess with your search engine rankings....
Is that true? What have you heard?





I have no idea about search engine rankings... but honestly I doubt it. Most sites use javascript. And they get ranked pretty well. Perform a search for any keyword, check the source code of the three top listed and bet that they use javascript.
As long as your javascript is correctly declared, the validation shouldn't be a problem.





Well.. just to make things clear... My advice is that you don't care about the time it takes for your pages to load... as long as it's not too long, that's fine. Avoid yourself the javascript hassle. And if not absolutely needed, bg images should not be used.





That's not quite right, I think. I remember reading recently about the order that elements in a page are loaded, and one of the points was that most browsers will load CSS background-image images last of all. Unfortunately I can't remember where I read it.Originally Posted by duuudie
Bookmarks