As per Yahoo's much-ballyhooed Best Practices for Speeding Up Your Site, we serve up static content from a CDN using far-future cache expiration headers. Of course, we need to occasionally update these "static" files, so we currently add an infix version as part of the filename (based on the SHA1 sum of the file contents). Thus:




However, managing the versioned files can become tedious, and I was wondering if a GET argument notation might be cleaner and better:


Which do you use, and why? Are there browser- or proxy/cache-related considerations that I should consider?

  • The reason I ask is that I seem to recall hearing a reason NOT to use the GET-argument style, but I can't remember why. – David Eyk Nov 5 '10 at 13:44
  • Doesn't using the GET-argument require serving the stylesheet with some kind of server side script (And it would no longer be static)? – Lotus Notes Nov 5 '10 at 20:43
  • @Lotus: You can send the GET-arguments and they will be silently ignored if nothing is looking for them. – David Eyk Nov 8 '10 at 14:20

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.

| improve this answer | |
  • 3
    I wonder if the information regarding query string caching and proxy servers is a bit dated? Google's docs no longer reference query strings and proxy servers in this context. Although the examples do still involve changing the filename itself. Squid 2.7 (2008) and 3.1 (2010) reportedly support query string caching by default, and earlier versions could be configured to support this. – MrWhite Oct 25 '15 at 0:32

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.

| improve this answer | |
  • That's the caveat I was trying to remember. Thanks for the link. – David Eyk Nov 8 '10 at 14:19
  • One way query strings are problematic: on the server, there's only one file, but any query string is a different URL. You use versioning when you're using caches, and since each new version is supposed to be immutable, you will use extremely long caches. If you're using a reverse proxy, it's possible (albeit unlikely) for someone to attack your server by GET'ng a version you haven't created yet. E.g. you only have style.css?v=3, but someone GET's style.css?v=4. Now that file is cached in the reverse proxy. When you upload the 4th version, the proxy still serves the 3rd one it cache previously. – OdraEncoded Jun 1 at 19:39
  • @OdraEncoded You could always use the file hash as the query string, then it's not possible to guess what the next version will be. Or expire the new query string during the build process. – DisgruntledGoat Jun 2 at 11:24
  • If you use hashes it's probably never going to happen, but not mathematically impossible, and invalidating the reverse proxy caches adds complexity to the project. Imho, the safest way to do this is simply returning 404 when a non-existent version is requested. There's no reason for the latest version stored in the server to be returned in deployment (though maybe it makes sense in a development server), so the simplest solution is to use versions in filenames rather than in query strings. – OdraEncoded Jun 3 at 17:03

Both will work equally well as a query string is considered part of the URL and by changing it you are in effect changing the name of the resource thus causing the browser to fetch a new copy of the file.

I say use whichever method is easier for you to maintain.

| improve this answer | |

this is not an answer to the above question, I want a better solution so I am asking here itself

Both of the methods would require modification to the files where the css and js files are referred. So in effect it would require a restart of the application server after making the changes.

Is there a better way, where versioning of static files can be handled without having to restart the Application server ?

the following is ruled out in the solution

  • changing the css and js filenames
  • passing a query paremeter in the url

the solution also should not affect setting cache-control or expires.


| improve this answer | |
  • 1
    looks like you're new here. This is a good question. You should post it as such, perhaps linking back to this question for reference. I've flagged this for moderator attention so they can help you. – David Eyk Jan 21 '11 at 17:54
  • as David pointed out, this site is not like other forum sites. If you have a new question to ask, feel free to click the "ask a question button" – Mark Henderson Jan 22 '11 at 2:29
  • This is a useful clarification. If you change your stylesheet, it would be preferable to keep the name and reference to the same, rather than updating hundreds of references to it across the site. – Mark Stosberg Jun 1 '12 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.