Forum Moderators: open

Message Too Old, No Replies

Preloading images

how to download an image just once.

         

IanTurner

9:28 am on Apr 6, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I have an interesting problem with preloading images.

I have 8 images I wish to rotate in four slots on my site.

I have set the images to preload (using Macromedia's preload script)

I also set up a timer onload to do the image rotations.

What happens when you load the page is that the images are reloaded every time the timer calls for them again. Causing an immense strain on the connection/server.

If you then use the back button to leave the page and forward button to go back on to the page it works fine and the images then swap without reloading at each call of the timer program.

Code snippets below:

function StartHome(){
setTimeout("ChangeHome()", 1000);
}

function ChangeHome(){

if (startNo > 8)
{
startNo = 1;
}

//document.images['pic1'].src=arImageList[startNo].src;
// MM_swapImage('pic1','', arImageList[startNo].src);
//MM_swapImage('pic2','', arImageList[startNo+1]);
//MM_swapImage('pic3','', arImageList[startNo+2]);
//MM_swapImage('pic4','', arImageList[startNo+3]);
MM_swapImage('pic1','', 'images/51170keepfit.jpg');
MM_swapImage('pic2','', 'images/87034column.jpg');
MM_swapImage('pic3','', 'images/87070twoback.jpg');
MM_swapImage('pic4','', 'images/87076wait.jpg');
startNo++;
setTimeout("ChangeHome()", 1000);

}

onload="MM_preloadImages('images/51133basket.jpg','images/51170keepfit.jpg',
'images/87034column.jpg','images/87070twoback.jpg','images/87076wait.jpg',
'images/87111shape.jpg','images/87123bike.jpg','images/87149plane.jpg');
StartHome();"

I need some ideas of how to get the images to load just once so that they don't overload the connection.

<I added linebreaks to the code to eliminate horizontal scrolling on the page - Tedster>

(edited by: tedster at 9:58 am (utc) on April 6, 2002)

tedster

12:20 pm on Apr 6, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's a new one to me. I know you only posted partial code. In your full code, do you include the definitions for MM_swapImage() and MM_preloadImages()?

IanTurner

12:57 pm on Apr 6, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Yes the MM_preloadImages and MM_swapImage functions are defined.

IanTurner

2:35 pm on Apr 6, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Score 1 to Opera,

It behaves as intended in Opera, however IE5.5 and NS6.2 show the problem symptoms

ggrot

5:35 pm on Apr 6, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That is odd, are you sure that your server isn't sending no-cache headers? That wouldn't make much sense either I guess, but its a thought.

IanTurner

7:07 pm on Apr 6, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



It shouldn't be sending no-cache headers, but I'm going to check that out, might also set an expiry date on the image folder.

IanTurner

9:57 pm on Apr 6, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Thanks ggrot, I got it sorted by specifying an expiry on the images directory.