It has bitten me several times during development too, some browsers have really aggressive caching schemes. Debugging problems caused by a stale CSS/JS file is just not fun.
Really, if we take a step back from the minify dream, the simple solution here is to append some kind of version number to the file. Then new HTML should have filenames with new version numbers so clients can't used their old cached files because the paths don't match.
I've found a really simple way to automate this transparently for a project by modifying one line in
Since common file systems don't provide version numbers on the files they store, we'll use the modification timestamp instead. And instead of renaming files to contain the version number, we'll just append a
?_=timestampto the URL:
<img src="/media/images/logo.png?_=4321234">Everything after the
?is ignored when looking up in the file system by the static file web servers I've tested so far. So it just works.
As a bonus, when this is running, you can safely modify the web server serving the static files to set an expiration date far out in the future for files requested with
?_=xxxxx. This allows an aggressive, yet perfectly safe caching scheme to be employed by any upstream cache, including the browser.
The above trick can be done in about 50 lines of Python. You can grab the little self-contained middleware module
modtimeurls.pyfrom my brand-new Garden of Python. It has been in production on several sites for over a year. The only problem I've found so far was with a PNG transparency fixer for IE6 that assumed
.pngfiles would end with