开发者

JavaScript Source Query

While browsing the code of some websites I sometimes notice that some JavaScript files are 开发者_如何学Cincluded like this:

  <script type="text/javascript" src="javascripts/jquery.js?1252521516"></script>

But I don't see what the jquery.js ?1252521516 part of the src parameter does. Can anyone explain this to me please?


It allows websites to force browsers to update their cached version of a script or other resource.

For example, when the Javascript code on that website changes, the number at the end would be changed. The browser would see as a totally new file, meaning it would not use whatever outdated, cached version it had previously downloaded. This gives you all the benefits of caching with the ability to bypass the cached version at any time.


It's known as a cache breaker. It stops the browser using an old version of your javascript due to caching rules.


The purpose of the query string is to prevent browsers from caching an old version of the file. Whenever the file is updated, the number in the query string is changed to force the browser to download the new version instead of using the one in its cache.


Probably some way to avoid caching (the 1252521516 part is generated each time the page is loaded), but I don't see why this is used for jquery

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜