[英]Browser cache - versioning files - but what if browser uses old version?
Say I have a JavaScript SPA that loads one file X_version1.js into the browser, and that file will be run. 假设我有一个JavaScript SPA,它将一个文件X_version1.js加载到浏览器中,并且该文件将运行。 What is preventing X_version1.js from accidentally calling a function in X_version0.js that was cached in the browser at an earlier time?
是什么防止X_version1.js意外调用X_version0.js中早先缓存在浏览器中的函数? Are cached .js scripts not invoked unless they are explicitly invoked and under what circumstances could that happen?
除非显式调用缓存的.js脚本,否则它们是否会被调用?在什么情况下会发生这种情况?
This doesn't seem that far-fetched, because sometimes we use cached versions of jQuery, or whatever, which might not be inside the .js file that is loaded in the most recent server request... 这似乎并不牵强,因为有时我们使用jQuery的缓存版本,或其他形式,它们可能不在最新服务器请求中加载的.js文件中...
The caching doesn't happen at the method level it happens at the file level. 缓存不在方法级别发生,而是在文件级别发生。
So if you have 所以如果你有
<script src="X_version0.js"></script>
Then the browser goes "ah I've downloaded that before! I'll just return the cached version." 然后浏览器显示“啊,我之前已经下载了它!我只返回缓存的版本”。 But when you change your source to:
但是,当您将来源更改为:
<script src="X_version1.js"></script>
The browser hasn't seen that file before and goes and fetches it. 浏览器之前并没有看到该文件,无法继续获取该文件。 At this point nothing in the page says load version0 so the browser doesnt
此时,页面上没有任何内容表明加载了version0,因此浏览器没有
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.