var image = new Image();
image.src="pathToTheFile";
The above code is called 25 times (with different pathToTheFile)
within a loop.
I manually checked the cache directory and not all images are cached,
sometimes it's only 3, sometimes 4, etc,
and mostly only the last few images within the loop.
However, if I put an alert message in between the lines
var image = new Image();
alert("BLAH");
image.src="pathToTheFile";
Before I click ok on the alert popup, I check the cache directory, and
then click the next alert, and so on.
All images are cached, i.e. everytime I check the cache directory, the
image that is supposed to be preloaded is cached as expected.
At first I thought that it might be caused by the delay before I click
ok on each alert. So I call a 'pause' function to replace the alert,
here's the pause function code
function pause(numberMillis) {
var now = new Date();
var exitTime = now.getTime() + numberMillis;
while (true) {
now = new Date();
if (now.getTime() > exitTime)
return;
}
}
I have also tried replacing the pause function with window.setTimeout
function.
I tried lots of pause/timeout value (in millisecond) and same problem
occured
All these were tested on several workstation with IE5, IE6, and NS7.
Any idea what might cause the problem? And how to fix it?
Please correct me if my attempt to put a delay before the image.src is
actually leading me to the wrong direction.
Thanks in advance.