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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opinion -- best pre-load image script?

Status
Not open for further replies.

RenoWV

Technical User
Mar 16, 2002
156
US
When I find javascripts that I might need to use, I put them in separate folders based on what they do. I have about a dozen for &quot;pre-loading&quot;, some of which are quite simple, others more complicated. Most do all the pre-loading of images in the <head>, whereas a few have the script in the head but call the preload image paths in the <body onLoad=....> tag.

Does anyone have an opinion about what they consider to be the best preloading image script -- one that they actually use and *know will work* in a cross browser platform? Thanks...

 
I prefer method that Adobe Photoshop generates for roll-over images. I.e.

var preloadFlag = false;
function preloadImages() {
if (document.images) {
anyname1 = newImage(&quot;path_to_image_1&quot;);
anyname2 = newImage(&quot;path_to_image_2&quot;);
...
preloadFlag = true;
}
}

It works for most browser types.

Regarding to <body onLoad=....>. It is better, to call preload function from onLoad. Both ways work. However, most browsers have limitation for number of connections opened at once. If page contains images more than limit, browser puts the rest images in the connection queue.
So, if you put preload calls just in the <head>, preloading images will be downloaded first and you will have had a delay for dowload page itself (primary images will be shown later).

Regards,
Sergey Smirnov
 
Thanks Sergey for the suggestion and the explanation. I'll try that when I next need one. Here's the preload script that I most recently used -- I can never quite tell whether it is working or not (with DSL the items loading flash by so quickly it is hard to see):

Code:
var myimages=new Array()
function preloadimages(){
for (i=0;i<preloadimages.arguments.length;i++){
myimages[i]=new Image()
myimages[i].src=preloadimages.arguments[i]
}
}

preloadimages(&quot;firstimage.gif&quot;,&quot;secondimage.gif&quot;,&quot;thirdimage.gif&quot;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top