开发者

adding on ?v=1 to urls

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 ext开发者_Go百科ernal css and js urls.


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜