开发者

Why do some websites access specific versions of a CSS or JavaScript file using GET parameters?

开发者 https://www.devze.com 2022-12-19 00:04 出处:网络
I have seen quite a lot of websites doing this (even stackoverflow itself) within their generated HTML source, accessing a 开发者_JS百科specific version of a CSS or JavaScript file with GET parameters

I have seen quite a lot of websites doing this (even stackoverflow itself) within their generated HTML source, accessing a 开发者_JS百科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?


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.


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.


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


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.

0

精彩评论

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

关注公众号