470,644 Members | 1,202 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,644 developers. It's quick & easy.

Image Cache

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[i].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
Jul 20 '05 #1
2 2081
On 7 Jan 2004 08:42:29 -0800, jo*********@jpmorgan.com (jubes) wrote:
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[i].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.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #2
jubes wrote:
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[i].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
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Ken | last post: by
16 posts views Thread by Donjuan | last post: by
2 posts views Thread by Marwin | last post: by
1 post views Thread by Giggle Girl | last post: by
2 posts views Thread by thehuby | last post: by
62 posts views Thread by ivan.leben | last post: by
6 posts views Thread by Mark Denardo | last post: by
4 posts views Thread by =?Utf-8?B?TWlrZQ==?= | last post: by
1 post views Thread by Korara | last post: by
reply views Thread by warner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.