473,322 Members | 1,806 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,322 software developers and data experts.

Preloading Image

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) {
if (typ == 'bad') {alert('bad image') ; return}
document.images.main.src = tester.src
}
Problem, at least on my local html copy. When my IE6 loads the image,
tester.src changes from "image.jpg" to
"file:///C:/Inetpub/wwwroot/mas/image.jpg". document.images.main.src =
tester.src", therefore, doesn't work. Question. After my onload, if I
did document.images.main.src = "image.jpg", wouldn't another copy of
"image.jpg" have to load?

I was thinking. Couldn't I set the object document.images.main to the
object tester? If so, how?

This may be no big deal, but I'd like my offline copy of my web site to
work like my online copy...Dennis
Jul 23 '05 #1
4 1654
On Sun, 20 Mar 2005 15:26:44 -0500, "Dennis Allen"
<de****@dennisallen.com> wrote:
After my onload, if I
did document.images.main.src = "image.jpg", wouldn't another copy of
"image.jpg" have to load?


No, that isn't how preloading works, it's all about URI's it's got
nothing to do with what you put in the document, if the URI's the same
then the browser _may_ cache it.

Browsers rarely cache file:// resources not surprisingly...

Jim.
Jul 23 '05 #2

To do my good deed as someone gave me a hand with some problem I had:

What you are implying is caching of the image and it depends on the
settings of the browser whether it will cache an image or download it
every single time.

If the settings of the browser lean toward using cached objects rather
than downloading everything, then so long as you give the exactly the
same location of the object, the browser will use the cached object.

Preloading objects is all about getting objects ready for event
processing (i.e. changing an image on a mouse over) where speed is of
the essence. But I suppose you could use it to force caching.

I wouldn't trust testing locally as your browser will sense that you
are local and won't cache!

Paul

On Sun, 20 Mar 2005 15:26:44 -0500, "Dennis Allen"
<de****@dennisallen.com> wrote:
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) {
if (typ == 'bad') {alert('bad image') ; return}
document.images.main.src = tester.src
}
Problem, at least on my local html copy. When my IE6 loads the image,
tester.src changes from "image.jpg" to
"file:///C:/Inetpub/wwwroot/mas/image.jpg". document.images.main.src =
tester.src", therefore, doesn't work. Question. After my onload, if I
did document.images.main.src = "image.jpg", wouldn't another copy of
"image.jpg" have to load?

I was thinking. Couldn't I set the object document.images.main to the
object tester? If so, how?

This may be no big deal, but I'd like my offline copy of my web site to
work like my online copy...Dennis


Jul 23 '05 #3
"Jim Ley" <ji*@jibbering.com> wrote in message
news:42****************@news.individual.net...
On Sun, 20 Mar 2005 15:26:44 -0500, "Dennis Allen"
<de****@dennisallen.com> wrote:
After my onload, if I
did document.images.main.src = "image.jpg", wouldn't another copy of
"image.jpg" have to load?


No, that isn't how preloading works, it's all about URI's it's got
nothing to do with what you put in the document, if the URI's the same
then the browser _may_ cache it.

Browsers rarely cache file:// resources not surprisingly...


Every preload example I've seen goes src = src. Just checked my old
Windows 98 machine. It has IE6 which also adds "file://" to tester.src.
Is it possible to set the <img> object with the Image() object?
Jul 23 '05 #4
On Mon, 21 Mar 2005 00:01:26 -0500, "Dennis Allen"
<de****@dennisallen.com> wrote:
"Jim Ley" <ji*@jibbering.com> wrote in message
No, that isn't how preloading works, it's all about URI's it's got
nothing to do with what you put in the document, if the URI's the same
then the browser _may_ cache it.

Browsers rarely cache file:// resources not surprisingly...


Every preload example I've seen goes src = src. Just checked my old
Windows 98 machine. It has IE6 which also adds "file://" to tester.src.
Is it possible to set the <img> object with the Image() object?


No, there's no such thing as an image object with any actual image
information in it, and it's completely irrelevant to the ability to
cache it.

I can't think off hand a of a browser that does not expand the url to
the full one in img.src

Jim.

Jul 23 '05 #5

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

Similar topics

22
by: Fabian | last post by:
var preload1 = new Image(); preload1.src = "/pic/yay.gif"; var preload2 = new Image(); preload2.src = "/pic/nay.gif"; The above is meant to preload image files, yes? Problem is, it doesnt seem...
2
by: Julie | last post by:
Hi, I'm trying to change images on a website without reloading the whole page and use the following code to preload the images: var preloadFlag = false; function preloadImages() { if...
6
by: michaaal | last post by:
Is this the correct way to preload an image...? Var Image1 = new Image() ....And then when I'm ready to use the image I can do this...? Button1.src=Image1.src ....Or am I just telling...
2
by: Stevio | last post by:
In my web page I preload images so that when a user clicks on a part of the image, the image changes. The images are used to display 4 tabs. Each image shows a different tab as highlighted. If a...
2
by: windandwaves | last post by:
Hi Gurus Preloading images has got to be JS 101. However, it does not seem to be working. Here is the function that I am using. I added the alerts to make sure it is working and all the right...
40
by: Geoff Cox | last post by:
Hello, I am still having problems - apologies if the answer is in previous postings! I now have, in the header, <sctipt> var myimages=new Array();
2
by: sachaburnett | last post by:
Hi everyone! I'm new to Javascript and am finding so much useful information on this group, so thanks to you all! I have a question about preloading images for onmouseover/out effects and...
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...
7
by: Keith Hughitt | last post by:
Hi all, I am having trouble preloading images in a javascript application, and was wondering if anyone had any suggestions. Basically I have a bunch of images stored in a database as BLOBs. At...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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)...
1
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.