Image preload: Not all images are cached

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Harod Ruthgar

    Image preload: Not all images are cached

    var image = new Image();
    image.src="path ToTheFile";

    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="path ToTheFile";

    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(numberMil lis) {
    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.setTimeo ut
    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.
  • Erwin Moller

    #2
    Re: Image preload: Not all images are cached

    Harod Ruthgar wrote:
    [color=blue]
    > var image = new Image();
    > image.src="path ToTheFile";
    >
    > 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="path ToTheFile";[/color]

    Hi,

    I think your problem can be fixed easily by using a fresh imageholder every
    time you load, and not put them all in the same var.
    Use an array of Images and assign each image to a new place in the array.

    Good luck.

    Regards,
    Erwin Moller

    Comment

    Working...