JavaScript 源查询
在浏览某些网站的代码时,我有时会注意到一些 JavaScript 文件是这样包含的:
<script type="text/javascript" src="javascripts/jquery.js?1252521516"></script>
但我看不到 src 参数的 jquery.js ?1252521516 部分的作用。有人可以向我解释一下吗?
While browsing the code of some websites I sometimes notice that some JavaScript files are included 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
它允许网站强制浏览器更新脚本或其他资源的缓存版本。
例如,当该网站上的 Javascript 代码发生更改时,末尾的数字也会发生更改。浏览器将视为一个全新的文件,这意味着它不会使用之前下载的任何过时的缓存版本。这为您提供了缓存的所有好处,并且能够随时绕过缓存版本。
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.
它被称为缓存断路器。由于缓存规则,它会停止使用旧版本 JavaScript 的浏览器。
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.
可能是避免缓存的某种方法(每次加载页面时都会生成 1252521516 部分),但我不明白为什么这用于 jquery
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