7

When aggressively caching CSS and other files, you can force the user to update to the latest version of the stylesheet by renaming the file and linking to the new copy (eg, style.123.css renamed to style.124.css). A different method often used instead of renaming the file is to pass a URL parameter, (eg, style.css?ver=123 which is later changed to style.css?ver=124).

Do all browsers support the latter method for downloading a new copy of the stylesheet? Are there any disadvantages to using the URL parameter over renaming the file?

Chris Morris
  • 316
  • 2
  • 9
  • 1
    Old browsers didn't cache urls with query strings (this might be due to an old RFC recommendation or something). Avoiding query strings is the safest bet. – Frank Farmer Feb 09 '13 at 03:01
  • Thanks - I had a feeling! Yep, it's back to the good ol' style.XXXXX.css for me :P – Chris Morris Feb 09 '13 at 03:03

2 Answers2

5

After further research, it turns out that some proxy caching services will not cache files with query strings in the URL. Whether this is true for some web browsers, I don't know.

So this seems to be the only major disadvantage of using query strings to update aggressively cached files - they may not cache at all.

Chris Morris
  • 316
  • 2
  • 9
1

The only way a browser could not "support" query-parameter controlled caching is if the browser used the cached version retrieved using a different parameter value. I have never heard of a browser that did that. So yes, all browsers support this technique. The only disadvantage I can think of is that you can't host multiple versions of the resource simultaneously. (assuming you are using static files)

recursive
  • 83,943
  • 34
  • 151
  • 241
  • I figured as much, I just wasn't sure if it may have been handled differently by older browsers - for example, I wasn't sure if older browsers ignored the query parameters in the and cached the style.css file. Yeah, that's true re: disadvantage. My setup has HTML files set to expire in 1 minute (soon to be upped to 2 weeks), and the CSS is set to expire max (2038). So it doesn't turn out to be a major issue because the HTML updates and links to the new file often - no missing stylesheets or anything. – Chris Morris Feb 07 '13 at 07:13
  • 1
    After a bit more research, it turns out that some proxy servers don't cache files that contain query string. – Chris Morris Feb 09 '13 at 02:54