Mobile app version of vmapp.org
Login or Join
Ann8826881

: What's the best way to version CSS and JS URLs? 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

@Ann8826881

Posted in: #CacheControl #StaticContent

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:

styles.min.css


Becomes:

styles.min.abcd1234.css


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

styles.min.css?v=abcd1234


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

10.04% popularity Vote Up Vote Down


Login to follow query

More posts by @Ann8826881

4 Comments

Sorted by latest first Latest Oldest Best

 

@XinRu657

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.

10% popularity Vote Up Vote Down


 

@YK1175434

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.

thanks

10% popularity Vote Up Vote Down


 

@Yeniel560

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.

10% popularity Vote Up Vote Down


 

@Kevin317

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme