473,725 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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


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
4039
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 images (+40) in a single image placeholder on ONE page - pre-loads multiple images - on a click of a mouse changes to the next image - on a click of a mouse changes to the previous image
11
2511
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 the sample. The image is loaded again every time I go over the thumbnail. Is there a solution for havint just one load? function AddImage(url) {
2
1424
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 for instance an image swap? Thanks very much for feedback,
4
1690
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() tester.onload=function() {cImg('good')} tester.onerror=function() {cImg('bad')} tester.src="image.jpg" } function cImg(typ) {
14
2786
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 they look bad. So what is the best way to resize an image. I'm not too concerned about size, but I guess I would like to compress it on the upload. Any thoughts?
62
17824
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(); img.src = ; Then I use the image a few more times by adding it into an Array object:
3
3937
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 a frame is drawn around it with resize and rotate buttons. Now it happened to me that I replaced these buttons (32x32) with larger images (48x48). The filenames were not changed, I only copied the new images over the old ones. Then I reloaded the...
7
2454
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 happening because the Images are not cached (yet) on the users browser. I tried preloading images with the 2nd code below in the childpage head and in the parent page head and both. no joy, dosent seem to actually 'preload' the pics. (i also gave...
0
8888
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9113
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8097
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.