in reply to Re^2: Slightly OT: Stop caching images
in thread Slightly OT: Stop caching images

Aside from cache-related pragma's and standard content-expiration, you may wish to check out the 'ETag' HTTP header, which seems to be favoured by Internet Explorer for this kind of thing.

Using ETag, you uniquely idenify each 'version' of a resource, so if you want it to refresh, you send a different ID.

I find it better than appending ?12309821 to a request because:
-David

Replies are listed 'Best First'.
Re^4: Slightly OT: Stop caching images
by astroboy (Chaplain) on Mar 28, 2007 at 04:43 UTC

    I wasn't aware of the ETag (it sounds useful), but I'm not sure how to use it in practice.

    Image requests are handled by Apache not my code. Without using something like mod_perl, how would I intercept the request and set an appropriate ETag? Where would I get the version number from?

      You can chain handlers in Apache (eg: the second content-handler gets the output of the first content-handler). In this vain, you could have a mod_perl handler after the standard handler, which computes/fetches the ETag for the resource.

      If you need fine-grained control of caching, you'll probably want to use mod_perl anyway.

      An ETag is simply a unique resource identifier. The simplest scheme I can think of is to compute an MD5 digest of the file (say as hex), sending that as the ETag. That way, only if the file contents change, the browser will know if it must really refresh the file.

      -David.