Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: image preloading


Message #1 by "J. Kroezen" <j.kroezen@c...> on Thu, 22 Aug 2002 20:17:14 +0200
I do it like this

  <img src="img1.jpg" width="1" height="1" style="{ display: none; }" />
  <img src="img2.jpg" width="1" height="1" style="{ display: none; }" />
  <!-- ... ... ... -->

and when the images are needed later (many pages later)
they are already in the browser cache :)

the page with the "<img" tags takes a while longer to load, though

no need to rely on the browser having javascript
and if the browser doesn't understand the style thing
the images only occupy a 1 bit on the screen --> easy to hide :))


> -----Original Message-----
> 
> Hi there,
> 
> I was wondering if someone could help me with a little script that
> seems to do some image preloading... Does this realy speed up 
> image loading because the images get cached in the browser?
> var preloadFlag = false;
> function preloadImages() 
> {
>    if (document.images) {
>       for ( var i = 0; i < preloadImages.arguments.length; i++ ) {
>          trash = newImage( preloadImages.arguments[ i ] );
>       }
>       preloadFlag = true;
>    }
> }
> 
> <body onLoad="preloadImages('infobutton_on.gif', 
> 'homebutton_on.gif');">
> ...
> </body>
> 
> Does someone know another way for image preloading.
> 
> Thanx,
>    Joey


  Return to Index