views:

60

answers:

3

As seen in the code from http://html5boilerplate.com/ (ctrl+f "?v=1") What does ?v=1 do exactly? It's tacked on to the external css and js urls.

+1  A: 

This is done to circumvent browser caching. The idea is that when these files change, you would increment the version number, thus forcing the file to be fetched by the browser again.

RedFilter
+4  A: 

It's just a cache-breaking method, for example:

myScript.js?v=1

I can (via cache headers) tell you to cache it forever, then when I push a new version, it's:

myScript.js?v=2

And your browser sees it as a new file it much fetch, and it can be cached forever as well, so basically you get the max cache benefit, and still force the client to re-fetch when a new version's out there. If possible, this version would be the result of a build process, automatically updated when the file changes (or at least a new build's, pushed, whatever the case may be).


As a real work example, look at the page you're viewing now:

http://sstatic.net/js/master.js?v=66ffcb6dcc55

It's a hash of the file...whenever it changes so does the hash on the end of the URL, and your browser will grab a new copy.

Nick Craver
So presumably should only be done, if you regularly expect you js file to change ?
spacemonkeys
No. If you expect your JS to change **infrequently**, you combine it with long expire times in the cache control headers.
David Dorward
@spacemonkeys - Yep, or not regularly as well, when you want to get the maximum caching benefit you can take this route...the bigger you are the more bandwidth *not caching* eats, and the more important this becomes.
Nick Craver
@David - There's no harm whether it changes frequently or not, this works in both scenarios equally well, minimizing the number of HTTP requests a client needs to make to ever get current or new files.
Nick Craver
@All ... sorry I think I slightly miss read the answer, v1 = do it if you expect you file never to change, which has a performance benefit
spacemonkeys
A: 

It doesn't do anything, per se.

It is just part of a URL. It follows the usual pattern for a query string, so a server side process might pay some attention to it and modify the script.

Most likely, it is just a change in the URL which will still serve up a static file from exactly the same location … but as the URL is different to v=0, it will break any caching to ensure that the browser fetches a version that was at least as new as the newest when the page was updated to use that URL for the script.

David Dorward