Forum Moderators: open

Message Too Old, No Replies

Script to load images for the next page

         

kapow

6:30 pm on Sep 12, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I want the front page to load, then to load the images for the next page (while a visitor is reading the front page). I have tried placing this at the end of the first page - but it doesn't work. Any help :(

<script language="JavaScript">
MM_preloadAllImages('
images/soandso1.gif','
images/soandso2.gif','
images/soandso3.gif','
images/soandso4.gif','
images/soandso5.gif'')
</script>

tedster

7:03 pm on Sep 12, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



From our generic javascript thread [webmasterworld.com].

When you've got a very likely-to-be-clicked link to a page with a large graphic or graphics, you can pre-load the graphic while your visitor is reading the earlier page. Then it's already in the cache and loads instantly if they click through.

At the very bottom of the BODY section, so your script doesn't interfere with the page that's being rendered:

<script type="text/javascript" language="JavaScript">
<!--
image01=new Image(www,hhh)
image02=new Image(www,hhh)

image01.src="fatone.gif"
image02.src="biggie.jpg"

//-->
</script>

toadhall

8:10 pm on Sep 12, 2002 (gmt 0)

10+ Year Member



If you want to guarantee preloading skip the javascript and simply "call" each image at the bottom of the preload page with widths and heights set to 1 pixel:

<a href="pix.gif" width="1" height="1" border="0">

The images will display as all but invisible pepper grains (1 pixel), but now they're in the browser's cache and will load quickly on subsequent pages

dhdweb

8:22 pm on Sep 12, 2002 (gmt 0)

10+ Year Member



Why did I never think of doing that?

Any downfalls to doing it that way?

buckworks

8:29 pm on Sep 12, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



What happens if the person moves to the next page when the image has only partly loaded? Does the image load have to start over, or can it just continue where it left off?

tedster

8:38 pm on Sep 12, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Does the image load have to start over, or can it just continue where it left off?

It needs to begin again.

Any downfalls to doing it that way?

Besides the flecks of pepper?

Depending on your layout and what browser is being used to access the page, the download of these "bottom feeders" may delay the rendering of the images up top - the ones that belong to the page content itself. As far as the browser can tell, they DO belong to the page itself, so the rendering order might get funky.

toadhall

11:17 pm on Sep 12, 2002 (gmt 0)

10+ Year Member



As long as the initial page is designed to hold the visitors attention long enough to load whatever size and number of images you include (as you put it "while a visitor is reading the front page") you'll be all right. Of course anyone who has visited previously may skip through to the photo page before they're all loaded, so the guarantee comes with a "limitations" clause. The pepper flecks don't show up unless you're looking for them so that's not a worry. Use in moderation - as always.

kapow

8:57 am on Sep 13, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Tedster - I will try it.

The front page is for a Flash intro (sorry to use the 'F' word, the client came to me with a Flash intro and wants to keep it). I will place the image loader
> At the very bottom of the BODY section, so your script doesn't interfere with the page that's being rendered.
However the page that's being rendered is the Flash intro. I have added and nice obviouse 'Skip Intro' link - I suspect one or two people will 'Skip Intro' and go to the 2nd 'menu' page (no more Flash). So, does that mean visitors who skip will get the menu images downloading all over again? - I see no way out of that so guess I will have to live with it. Will visitors who sit back to watch to very exciting Flash intro get the 2nd page nice and quickly?

Re. <a href="pix.gif" width="1" height="1" border="0">
Hidden links: Isn't this seen as a method of spamming by Google?

tedster

9:12 am on Sep 13, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



...one or two people will 'Skip Intro' and go to the 2nd 'menu' page (no more Flash). So, does that mean visitors who skip will get the menu images downloading all over again?

If they didn't stay on page 1 long enough for background downloads to finish, yes, that's what will happen - but it will just be a problem with the images that were incomplete downloads.

I never tried this on a Flash page - I'm guessing that the javascript might not kick in until the whole Flash movie is downloaded! You might have better luch with the cracked peeper method! It's worth a couple experiments, I'd say.