Discussion:
IE refuse to cache redirected image? Bad HTTP protocol?
(too old to reply)
Samuel
2004-10-17 15:23:53 UTC
Permalink
Is there anyway to get IE to cache a redirected image? For example, I have
a page with the following:

<html><body>
<img src=http://site1.com/redir.php?id=12>
</body></html>

The image is redirected to a different location through a script. If I don't
redirect and just point to the final image, IE caches the image properly.
Why is Internet Explorer not caching my image? Mozilla and Opera works
correctly. See the headers below
(today's date is Oct 5).


+++GET 1+++
GET /redir.php?id=12 HTTP/1.1
Accept: */*
Referer: http://site1.com/
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR
1.0.3705; .NET CLR 1.1.4322)
Host: site1.com
Connection: keep-alive


+++RESP 1+++
HTTP/1.1 302 Found
Date: Tue, 05 Oct 2004 18:06:46 GMT
Server: Apache
Accept-Ranges: bytes
Location: http://site2.com/real.php?id=12
Content-Encoding: gzip
Cache-Control: max-age=86400
Expires: Wed, 06 Oct 2004 18:06:46 GMT
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8


+++GET 2+++
GET /real.php?id=12 HTTP/1.1
Accept: */*
Referer: http://site1.com/
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR
1.0.3705; .NET CLR 1.1.4322)
Host: site2.com
Connection: keep-alive


+++RESP 2+++
HTTP/1.1 200 OK
Date: Tue, 05 Oct 2004 18:10:35 GMT
Server: Apache
Accept-Ranges: bytes
Cache-Control: max-age=604800, s-maxage=604800
Expires: Tue, 12 Oct 2004 18:10:35 GMT
Content-Length: 3234
Connection: close
Content-Type: image/jpeg
Bruce Lewis
2004-10-18 18:08:24 UTC
Permalink
Post by Samuel
The image is redirected to a different location through a script. If I don't
redirect and just point to the final image, IE caches the image properly.
Why is Internet Explorer not caching my image? Mozilla and Opera works
correctly. See the headers below
(today's date is Oct 5).
I am generally dissatisfied with IE's lack of adherence to HTTP
standards, but I can't really fault them for this one. If a script is
redirecting to an image, who's to say that the image it happens to
redirect to this time is the one it will redirect to next time? If you
want the resource to be cacheable, the script should return the
appropriate headers.

On the other hand, if you change your script to return appropriate
headers, and IE still doesn't cache the result, then I would agree
there's a problem.
Samuel
2004-10-21 15:30:24 UTC
Permalink
I tried setting header to "301 Moved Permanently" and IE still wouldn't
cache the image. I have Win XP IE 6 SP1.

Any idea?
Post by Bruce Lewis
Post by Samuel
The image is redirected to a different location through a script. If I don't
redirect and just point to the final image, IE caches the image properly.
Why is Internet Explorer not caching my image? Mozilla and Opera works
correctly. See the headers below
(today's date is Oct 5).
I am generally dissatisfied with IE's lack of adherence to HTTP
standards, but I can't really fault them for this one. If a script is
redirecting to an image, who's to say that the image it happens to
redirect to this time is the one it will redirect to next time? If you
want the resource to be cacheable, the script should return the
appropriate headers.
On the other hand, if you change your script to return appropriate
headers, and IE still doesn't cache the result, then I would agree
there's a problem.
Bruce Lewis
2004-10-22 14:24:46 UTC
Permalink
Post by Samuel
I tried setting header to "301 Moved Permanently" and IE still wouldn't
cache the image. I have Win XP IE 6 SP1.
Any idea?
If your script always redirects to the same image, it should set the
Last-Modified: header to the mod time for the image file.
--
Make that pile of digital photos presentable: http://ourdoings.com/
It's quicker and easier than you think.
Alan J. Flavell
2004-10-22 17:03:27 UTC
Permalink
Post by Samuel
Is there anyway to get IE to cache a redirected image?
Aside from any oddities of behaviour by IE, there's two separate
issues involved here at the HTTP level:

1. the cacheability of the redirection itself
2. the cacheability of the document to which the redirection is
pointing.

These could be quite independent of each other, e.g there are
situations for redirecting temporarily, to a document which itself
is entirely cacheable; conversely, redirecting permanently to a
document which itself is transient and should not be cached.

To be honest, I haven't looked at your specific example in enough
detail to work out what you really want. I'm just trying to help in
terms of showing a way to partition the problem space (as the saying
goes).

If the redirection itself is a constant, then the appropriate status
code for the redirection is a 301 (permanent redirection), rather than
a 302.

Once the browser has followed the redirection, it's supposed to treat
the retrieval of the resource at the new URL pretty much the same way
as it would have done if the URL had been accessed directly.

You're aware, presumably, that the browser itself can be configured
for different kinds of behaviour vis a vis cached content? In the
case of I.Exploder, it's Tools -> Internet Options -> General /
Temporary Internet Files -> Settings, with a radio button having
four possible settings.

In case you haven't been there yet, I strongly recommend
Mark Nottingham's tutorial, http://www.mnot.net/cache_docs/
and the associated online "Cacheability engine".

The fact that the URL that's the destination of your redirection
itself has a query string in it, might be discouraging the browser
from cacheing something that's normally cacheable. But that's only
a hunch.

I'd suggest doing some tests without the redirection first, just going
straight to the URL without the detour, and seeing what's happening.
Then I'd worry about re-introducing the redirection, if it's really
necessary. Hope that at least gives some ideas to work on. Good
luck.

Loading...