Hacker News new | ask | show | jobs
by chias 3438 days ago
My preferred solution to this is to generate links to resources like that (CSS, JS, etc) dynamically.

For each filetype, set up your webserver such that `filename.[10-digits].css` is handled identically to `filename.css`. In apache, you can do this in .htaccess with a rule that looks something like:

    RewriteRule ^(.*)\.[\d]{10}\.(css|js|png)$ $1.$2 [L]
Then generate your links by throwing the file's last modified timestamp into the URL. The net result is that if the file changes, the URL changes, and so the cache no longer applies. It's better than using a "fake" parameter (e.g. file.js?v=2) because using fake parameters suggests that the file is dynamic, causing browsers and proxies to behave differently.