Connecting Tech Pros Worldwide Help | Site Map

Making an image download before the rest of the page does?

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 20th, 2005, 09:32 AM
Keiron Waites
Guest
 
Posts: n/a
Default Making an image download before the rest of the page does?

Hi,

Is there any JavaScript that can force the download of an image or a list of
images before the HTML, or any other images are downloaded? This is
necessary so I can force the background image to download before anything
else does.

TIA,

Keiron



  #2  
Old July 20th, 2005, 09:33 AM
VBDude
Guest
 
Posts: n/a
Default Re: Making an image download before the rest of the page does?

I do agree with Lasse Reichstein Nielsen that if the page is useless without
the background then redesign it.

On the other hand, why don't you look at the problem from the other
way. How can I hide the contents until the picture(s) are loaded ?

Use the following statement to hide everything inside a DIV:
document.getElementById("YourDivID").style.display = "none";

Use the following statement to show everything inside a DIV:
document.getElementById("YourDivID").style.display = "";


"Lasse Reichstein Nielsen" <lrn@hotpop.com> wrote in message
news:8yq6lk1m.fsf@hotpop.com...[color=blue]
> "Keiron Waites" <webmaster@-NOSPAM-sharemonkey.com> writes:
>[color=green]
> > Is there any JavaScript that can force the download of an image or a[/color][/color]
list of[color=blue][color=green]
> > images before the HTML, or any other images are downloaded?[/color]
>
> Not before all the HTML (the script has to come from somewhere), but
> you can start downloading simultaneously (up to the browsers limit of
> simultaneous connections).
>
> <script type="text/javascript">
>
> function preloadImg(src) {
> var dummy = new Image();
> dummy.src=src;
> }
> preloadImg("background.png");
> preloadImg("img1.png");
> preloadImg("img2.png");
> preloadImg("img3.png");
>
> </script>
>[color=green]
> > This is necessary so I can force the background image to download
> > before anything else does.[/color]
>
> This will not pause the HTML while you load the background.
>
> If your page is unusable unless the background image is loaded,
> then you should redesing your page.
>
> /L
> --
> Lasse Reichstein Nielsen - lrn@hotpop.com
> Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
> 'Faith without judgement merely degrades the spirit divine.'[/color]


  #3  
Old July 20th, 2005, 09:33 AM
cwdjr
Guest
 
Posts: n/a
Default Re: Making an image download before the rest of the page does?

If you are willing to use a preload page, you can load all of the
images before your page starts. Dynamic Drive at www.dynamicdrive.com
has ready-made preload pages. You can use most of them for free
provided you leave the Dynamic Drive credits intact in comments in the
script. They are easy to use. You have to set up two 1 x 1 px solid
color gifs for the colors of the status bar. You can position the
loading status bar as desired. You put in the URL of your main page to
which you automatically transfer as soon as preloading is completed.
You must fill in an array of URLs for your images. If your page takes
a bit of time to load you can include some text on the preload page to
keep the viewer busy while preloading. Also you can tell a viewer to
reload and/or turn on JS if there is no motion of the preload bar. A
preload page may not be right for every application, but it is a nice
trick to have at hand for many pages that otherwise produce problems.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.