What's the best way to version CSS and JS URLs?

Using the GET-style versioning, from a blank cache multiple URLs - e.g. style.css?v=123 and style.css?v=456 - would return the same content. However I can't see this would be problematic, especially since you'd only link to one at a time.

I think you'll find the GET-style much easier to maintain. You don't need separate files: just change the URL and browsers will fetch the CSS afresh.

UPDATE: on further research it appears that using a query string may stop browsers caching the files. However, if you are returning proper headers such as Expires this is not an issue.

UPDATE 2: the accepted answer points out that some proxies do not cache files with a query string. However this is based on old information; the particular issue they mention in Squid was fixed 7 years ago. Impressive Webs did a good write up on this.


According to Google's Make the Web Faster, pages with query parameters are not cached by many HTTP proxies.

Most proxies, most notably Squid up through version 3.0, do not cache resources with a "?" in their URL even if a Cache-control: public header is present in the response. To enable proxy caching for these resources, remove query strings from references to static resources, and instead encode the parameters into the file names themselves.

So styles.min.abcd1234.css is the preferred solution. You can use an appropriate URL rewriting mechanism to turn styles.min.abcd1234.css into the easier to implement styles.min.css?v=abcd1234 transparently.

If you support HTTPS only, that advice does not apply, because proxies can't normally cache pages that are served over SSL.