in reply to Slightly OT: Stop caching images

A very cheap trick to stop images from being cached is to diddle the URI in the <img> element on the page. Instead of emitting:

<img src="thumbnail-left.png"> <img src="thumbnail-right.png">

Into the outgoing page, add a bogus GET parameter that makes them unique:

<img src="thumbnail-left.png?4608fe05888c"> <img src="thumbnail-right.png?4608fe0ab9b9">

Which, unless you have some weird'n'wacky image handler, will be ignored by your server and the client will be forced to reload the images each time due to the GET parameter, which will inhibit its ability to cache.

And in case you were wondering, I generated the above with sprintf "%x%0x\n", time, rand(65535);. Adjust as appropriate.

This is far less hassle than having to fiddle around with cache/no-cache parameters.

• another intruder with the mooring in the heart of the Perl

Replies are listed 'Best First'.
Re^2: Slightly OT: Stop caching images
by astroboy (Chaplain) on Mar 27, 2007 at 11:49 UTC
    Duh, of course. I've done something similar with my Ajax calls, because IE caches the GET requests. Cheers for pointing that out