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 MikeeOK 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.

GaryC123

Programmer
Sep 10, 2002
1,041
NO
What I would like to do is preload all the images in a single directory, on the first page where a visitor will spend some time looking about the page, so that when the visitor goes to the next page all the images are stored locally on the visitors pc so then the second page loads really fast.
All i can find about this is for rollover images on the same page. is this possible? and how to do it? Saturday 12.00
im6.gif
im2.gif
im2.gif
20.00
im5.gif
im4.gif
im7.gif
3.00am
im8.gif
Sunday [img http
 
It doesn't matter whether images are on the same page or not. If you don't change their name and path, all preloaded images will be "ready" for all pages that you link them to.
Usually preloader scripts are duplicated on all corresponding pages, because you never know what page will be first that your visitor will load.
 
Ok Thx,
Now is their an easy way to preload the images without specifying each name (they're varying names not 1.jpg,2.jpg etc) kinda just saying *.jpg in folder Thumbs or something. And how do I preload them, fairly new java so not adept at it at all.
Cheers Saturday 12.00
im6.gif
im2.gif
im2.gif
20.00
im5.gif
im4.gif
im7.gif
3.00am
im8.gif
Sunday [img http
 
You have to specify each name - in this or other way.
The most simple is this:

if (document.images) {

im1 = new Image();
im1.src = "images/picture1.gif"

im2 = new Image();
im2.src = "images/picture2.gif"

. . .
}

If all images are named in similar way, like pictureNN.gif, you can do in a loop. Something like that:

if(document.images) {
total = 10; // total number of images to preload
for (n=0; n<total; n++)
{
document.images[n] = new Image();
document.images[n].src = eval('picture' + n + '.gif');
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top