Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preload Images

Status
Not open for further replies.

uniopp

Technical User
Oct 7, 2001
152
JP
Hi,
I'm using js similar to the the code below to preload my images.
All of my html pages have the same header (with the js preload code) included when they load.
I was wondering if it matters that my js preload code is repeated on each and every page load. Am I slowing the page loading down? Should I only include it on the first page to be loaded?
Thank you.

Code:
<SCRIPT LANGUAGE = JAVASCRIPT>
if (document.images) 
{
   img1 = new Image();
   img2 = new Image();
   img1.src = "imageName1.gif";
   img2.src = "imageName2.gif"
}
</SCRIPT>
 
If all of your pages are preloading the same images, then obviously, you would not require it on all of them (as all but the first would be redundant - assuming, of course, your visitors always arrived though the one page that had the preload code on).

If they are all loading different images, then obviously you would - otherwise these new images would never be preloaded.

Hope this helps,
Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Dan,
Thank you for your reply.
All of my pages have the same images plus a couple of extra ones on some pages. The problem is that I don't know which page each user will start on so it's easiest to load the images in the header which is included on every page.
What I really want to know is whether the preload code on every page is going to slow things down or if it will just be ignored if the images have already been loaded?
Thanks.
Simon.
 
Sorry,
Can you give me more details? I've looked in both Firefox and IE but can't determine which cache settings would affect whether the preloaded images are reloaded or just ignored.
Thanks.
 
It's not to do with preloaded images, but any content.

If a user has disabled caching, or has a cache that is too small, then your preloading code will have no effect.

Of course - you can't be held resonsible for what settings users change on their PCs, so you can only code for what a majority of users will have.

Assuming the cache is working as "normal", then your preload code should only have a small impact, as the browser would realise the image you are loading has already been cached.

Hope this helps,
Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top