473,320 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Image preload: Not all images are cached

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.
Jul 20 '05 #1
1 1882
Harod Ruthgar wrote:
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";


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
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Wonko | last post by:
Here's my problem if anyone could be so kind to help me out. I assume it's quite easy for an experienced programmer but I'm not one of them :) I have a JavaScript code that: - displays multiple...
11
by: Michel | last post by:
Here is a litle script that preload images and show a thumbnail. Once you get on the picture you see the real size It worsk fine with normal picture but when the url has some parameters like in...
2
by: magister | last post by:
Hello, Can anyone tell me with certainty? If I load a server-side image into a javascript image object. Is the image saved on the client, or does the page go back to the server when I do...
4
by: Dennis Allen | last post by:
Hi. I have one image that has to show up in a html page several times. To save time, I'd like to preload this image. As an example: if (document.images) { tester = new Image()...
14
by: Rudy | last post by:
Hello all! I been trying to get a handle with Images. I have learned alot from the fine people here. So, I also learned that thumbnail images look terrible taken from a digital cam. I know why...
62
by: ivan.leben | last post by:
How can I really delete a preloaded image from memory/disk cache? Let's say I preload an image by creating an Image object and setting its src attribute to desired URL: var img = new Image();...
3
by: kayahr | last post by:
Hi there, I have a strange problem in Internet Explorer (IE6 and IE7). I'm writing a JavaScript application which allows the user to edit a photo composition. So when the user selects a photo then...
7
by: Inny | last post by:
Hello again, Im using the code below in a child page (popup), the images are called from the parent page. When the changer is running, the child page goes white between images. I realise this is...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.