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

hmm ... I probably didn't explain myself very well. I am rotating an image (using Image::Magick's Rotate method) not changing the image order. So nothing about the web page has changed - but the image on the disk itself has rotated. I can't change the name of the image to prevent caching (other than to add redundant query info as above) as it's used throughout the system and by more than one module.

mod_headers could be useful, though. Thanks

Replies are listed 'Best First'.
Re^3: Slightly OT: Stop caching images
by erroneousBollock (Curate) on Mar 28, 2007 at 03:07 UTC
    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:
    • my logs arent filled with random numbers
    • 12309821 adds nothing to the document, semantically speaking.
    • the ETag header is generally left unmolested by internet proxies.

    -David

      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.