Image Cache

J

jubes

Hi,

I've been developing an intranet application that uses IE 5.5 and have
come across a problem, well sort of.

Since the application uses frames I use an array of Image objects to
cache the image in the top frame. Now replacing an exsiting the image
source on an existing image tag is easy (ie imgTag.src =
imgArry.src) and there is no HTTP request back to the server.

Now expanding that concept further if I create an image tag with
javascript by using divTag.innerHTML = '<img src="imgURL">' this
created tag will make an HTTP request to the server, and since I've
all ready cached all images the server returns a 304 (not modified)
and does not return image data.

So to avoid the HTTP request I tried divTag.innerHTML = '<img src=""
onerror="func(this)" imgIndex="1">'

where

function func(ref){
ref.src =imgArry[ref.imgIndex].src];
}

therefore in this case we have an existing image tag, albeit it throws
an error, and do the normal image replace. now in this scenerio it
still makes a HTTP request.

Why does the last scenario make a HTTP request? Also is there a way to
create an image tag on the fly without it making a HTTP request?

thanks
 
J

Jim Ley

Since the application uses frames I use an array of Image objects to
cache the image in the top frame. Now replacing an exsiting the image
source on an existing image tag is easy (ie imgTag.src =
imgArry.src) and there is no HTTP request back to the server.


That would all depend on the cache settings, if the above doesn't make
an http request, then I'm surprised an innerHTML call does, I've
never seen where the 2 are not absolutely equivalent.
Why does the last scenario make a HTTP request? Also is there a way to
create an image tag on the fly without it making a HTTP request?

Nope, but IE fully honours cache settings, and you really should not
have got this far without visiting htt://www.mnot.net/cache_docs/ do
so now, and your problems will go away.

Jim.
 
T

Thomas 'PointedEars' Lahn

jubes said:
Since the application uses frames I use an array of Image objects to
cache the image in the top frame. Now replacing an exsiting the image
source on an existing image tag is easy (ie imgTag.src =
imgArry.src) and there is no HTTP request back to the server.


No matter if it's only IE, do it the standards-compliant way
wherever you can (and you can here, without breaking functionality
but with cleaning up the namespace). You may want to port it
sometime. So do not use idOrNameOfElement.src but use
document.images["idOrNameOfElement"].src. And you better test
if document.images["idOrNameOfElement"] exists before you do
that. (You should do this with idOrNameOfElement as reference,
too.)


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top