简体   繁体   English

浏览器缓存-版本文件-但是如果浏览器使用旧版本怎么办?

[英]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.

相关问题 自动javascript版本控制以避免浏览器缓存清理 - automatic javascript versioning to avoid browser cache clean 在旧版浏览器中显示sankey - Display sankey in old browser version 您托管的文件上的浏览器缓存 - Browser cache on files you host 如何自动增加版本控制以便浏览器可以自动重新加载 JS/CSS 文件而无需手动清除缓存 - How to auto increase versioning so that browser can automatically reload the JS/CSS files without having to clear the cache manually 将javascript文件版本化为maven构建的一部分,以避免Web浏览器缓存 - versioning javascript files as part of maven build to avoid web browser caching Android浏览器仍然使用旧的Java事件创建方法 - Android browser still uses the old way of creating events in Javascript 如何要求浏览器缓存文件以备将来使用 - How to ask browser to cache files for future use 如何将JavaScript和CSS文件放入浏览器缓存中? - How to put JavaScript and CSS files in browser cache? 配置IIS以指示浏览器不缓存JavaScript文件 - Configure IIS to instruct the browser to not cache JavaScript files $(&#39;#textboxId&#39;).val() 返回旧值(浏览器缓存问题) - $('#textboxId').val() returning old value (browser cache issue)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM