...

View Full Version : how do you know if preloading works?



Tails
03-01-2003, 07:35 PM
Preloading never seems to work for me. Even for a split second or 2, I see 'X' before the page is done loading, why? And because of the lovely thing that you can't disable known as "cache", there's no way of knowing. I can't test it offline. I tried it on a floppy even after changing to another disk and then replacing the first and the images are still in Windows cache and not loading at floppy speed. And then online, servers handle cache on any files you have loaded and remain that way until that file is modified. Is the term "preloading" just a hoaxe? I want to make my own preload bar.

<script>
A=Array("20.gif","21.gif","22.gif","23.gif")
B=Array("a","b","c","d")
for (i=0; i<A.length; i++)
{
B[i]=new Image()
B[i].src=A[i]
grow()
}

function grow()
{
document.images[0].width+=50
}
</script>

<body>
<img src="z.gif" width="0" height="16" />
</body>

Will this work?

Graeme Hackston
03-01-2003, 08:02 PM
This might help

http://www.codingforums.com/showthread.php?s=&threadid=14836

brothercake
03-02-2003, 05:05 PM
The "z.gif" in your HTML is not the same image object as the one you created in script. Eg if I go

<script>
var myImg = new Image;
myImg.src = "picture.gif";

document.write('<img src="picture.gif">');
</script>

Then you won't see any benefit to the preload, because there's two images there; the fact that they both have the same URI is irrelevant - the browser still loads it twice.

But this is different; this only loads the image once:

<script>
var myImg = new Image;
myImg.src = "picture.gif";

document.write('<img src="'+myImg.src+'">');
</script>

Reno CF
03-03-2003, 03:19 AM
Thanks brothercake for the valuable information -- it is the first time I've read that explanation.

Quick question... If a person wanted to preload multiple images, is it just a matter of adding them in this manner:


<script>
var myImg = new Image;
myImg.src = "picture.gif", "picture1.gif", "picture2.gif", "picture3.gif";

document.write('<img src="'+myImg.src+'">');
</script>

brothercake
04-04-2003, 08:32 PM
Crossposted; the rest of the thread is at http://www.codingforums.com/showthread.php?s=&threadid=17645



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum