Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have seen quite a lot of websites doing this (even stackoverflow itself) within their generated HTML source, accessing a specific version of a CSS or JavaScript file with GET parameters. What's the point of it?

Example:

<link rel="stylesheet" href="http://sstatic.net/so/all.css?v=6230">
<script type="text/javascript" 
        src="http://sstatic.net/so/js/master.js?v=6180"></script>

Is it simply a manner of coherence or best practice? Is it simply so that clients with old cached versions on their browsers are forced to update their outdated version?

share|improve this question
add comment

4 Answers

up vote 4 down vote accepted

Is it simply so that clients with old cached versions on their browsers are forced to update their outdated version?

Exactly.

Check out this question for details, further links and discussion and this question on how Stack Overflow itself employs the method.

share|improve this answer
    
Thanks a lot for the information. I guess I guessed right :P. Again, a good practice seems to fetch the repository revision for the version number. I am using git, maybe git describe would do it but I'm wondering if there is still a popular way for generating the number without too much code change (changing version each time the css/js file is modified would be a bit tedious). I am thinking of using the file's modification date maybe? –  Steven Rosato Feb 5 '10 at 0:10
    
@Steven Rosato Good question. I don't know of such a way, you could of course use the general revision number but that would trigger the reload quite often. Anyway, if you can use URL rewriting, you can have every /12345/style.css point to the same style.css file, saving you the hassle of creating the actual directory when checking in. That way, you would have to worry only about how to call the style sheet. Maybe worth an extra question. –  Pekka 웃 Feb 5 '10 at 0:20
add comment

Yes, it is for bursting browser and proxy caches. There's no other purpose.

Well, theoretically you can dynamically generate javascript and then you'll need those parameters. JSONP works that way for example. But mostly it is for invalidate caches.

share|improve this answer
add comment

It's to force the browser get the new version and not simply use a cached, older version. That's it.

share|improve this answer
add comment

This is used with far future expiration for CSS/Javascript. This allows the site to tell your browser to cache the data for a very long time (e.g. 5 years). When the css or js is updated then the version number would change, forcing a cache miss.

Browsers cache the css/js by the full query string.

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.