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

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?

Replies are listed 'Best First'.
Re^5: Slightly OT: Stop caching images
by erroneousBollock (Curate) on Mar 29, 2007 at 14:10 UTC
    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.