View Full Version : Preloading Images
Kommodore-X
May 1st, 2001, 01:39 AM
By using this script:
<SCRIPT LANGUAGE="JavaScript">
<!-- hide from none JavaScript Browsers
Image1= new Image(175,50)
Image1.src = "image1.gif"
Image2 = new Image(25,30)
Image2.src = "image2.gif"
Image3 = new Image(125,80)
Image3.src = "image3.gif"
// End Hiding -->
</SCRIPT>
Do I have to fill in the height & width of the images also and what does the Image3.src mean?
Phunn Gye
May 1st, 2001, 06:53 AM
You don't really need the height and width values, but it doesn't hurt to add them.
As for what 'image3.src' means, the src part is a property of 'image3' that points to where the actual picture is stored in the image table that javascript sets up.
Take a look at any tutorial about DOM - document object model for more info. :D
Steven.Bentley
May 1st, 2001, 09:04 AM
The width and height are alleged to make the image display more quickly, mainly because the html is rendered with a gap the size if the image rather, so when it loads and it works out how big it is the page doesn't have to redraw.
Phunn Gye
May 1st, 2001, 02:11 PM
Steve; does that apply to javascript too, :confused:
Steven.Bentley
May 1st, 2001, 04:54 PM
Can't see why it wouldn't, but it's not too much effort to add the height and width is it? ;)
Buzz
May 1st, 2001, 05:08 PM
I'm with Steven. The width and height do increase page loads because the browser does not have to rearrange a page after an image has downloaded. It can simply leave a space the proper size. And yes. It applies to javascript as well but you wouldn't put width and height there in the head in this instance. You would put it in your html where the image is located.
The preload script doesn't actually display images so putting width and height is pointless, but if you have a javascript that does dipslay images you should put width and height.
Phunn Gye
May 1st, 2001, 11:17 PM
that's about what I thought. You don't realy need them. I usually put them in the html section as I place the images on the page. Even when I pre-load with height and width, I put it in again in the html.
Kommodore-X
May 2nd, 2001, 10:44 PM
Originally posted by Steven.Bentley:
<STRONG>Can't see why it wouldn't, but it's not too much effort to add the height and width is it? ;)</STRONG>
It is when you have to do it with 30 or so images.
Kommodore-X
May 2nd, 2001, 11:58 PM
Does the image.src mean that if I want to use the proloaded image I have to use image.src instead of image.jpg?
Phunn Gye
May 3rd, 2001, 03:31 AM
When you've preloaded the images, and want to use them in the html you use the name you gave the image.
example:
in the html of the page you have
<img src="image1.gif", border="0", height=...>
Instead of having to put the path in the image statement, you just refer to the src of the image.
Steven.Bentley
May 3rd, 2001, 11:00 AM
Originally posted by Kommodore-X:
<STRONG>It is when you have to do it with 30 or so images.</STRONG>
OK you've got me there :D
Buzz
May 3rd, 2001, 05:01 PM
Actually folks I would think on a page with 30+ images it would be imperative to include the width and height. After all ANYTHING that can be done to download the page faster you should do. 30 images will take enough time, eliminating the browser having to redraw the page would help the load speed. Why wouldn't you?
Kommodore-X
May 3rd, 2001, 10:38 PM
Just to clear this up 30+ images sounds like alot and you would think the page takes forever to load but they are only around 2K in size.
Steven.Bentley
May 4th, 2001, 03:39 PM
But 30+ page redraws - each time one loads :eek:
JustJay
January 17th, 2002, 07:00 PM
Is this applicable to preloading a page????
Steven.Bentley
January 17th, 2002, 08:37 PM
Not really, start a new thread and explain what you want to achieve :)