Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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?

share|improve this question
    
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
add comment

4 Answers

up vote 6 down vote accepted

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.

share|improve this answer
add comment

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

share|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
add comment

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.

share|improve this answer
    
That's the caveat I was trying to remember. Thanks for the link. –  David Eyk Nov 8 '10 at 14:19
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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