Monday, August 29th, 2005
>Thomas Fuchs (script.aculo.us / Rails fame) talks of his Internet Explorer and Ajax image caching woes.
Inserting chunks of HTML via Ajax is cool stuff, and speeds things up quite a bit. As long as you don’t happen to insert some images and you’re using Internet Explorer 6, that is.
imgtags or any tags with CSS background images, Internet Explorer will always try to redownload these images). Read the detailed account on this.
Microsoft says it’s designed that way. Well. Sure.
Also, the Cache-Control header, if set to something like
is not handled too well, as Internet Explorer will always try to revalidate the file (Safari and Firefox don’t, they will use their cached copy until the time given by
max-agehas elapsed, and only then will do the cache revalidation).
A workaround for this (not perfect, but as good as it gets) is to send proper Last-Modified, Cache-Control, and ETag HTTP headers, so Internet Explorer sends back an If-Modified-Since header trying to find out if it should refresh its cache. We can then just answer with a 304 Not Modified HTTP status, and IE will use the cached image anyway. (Note that IE suddenly seems to “remember” it has the image in the cache here!).
Posted by Dion Almaer at 3:46 am