简体   繁体   English

如何避免要求客户端清除浏览器缓存以获取最新的Javascript更改?

[英]How to avoid asking the clients to clear browser cache for the latest Javascript changes?

A client would report a bug in our JS-heavy app, we fixed it, but the client's browser still using the cached copy. 客户会在我们的JS大量应用中报告一个错误,我们已将其修复,但客户的浏览器仍在使用缓存的副本。 This happens a lot, and asking our clients to flush their browser cache seems very low-tech and troublesome. 这种情况经常发生,要求我们的客户刷新其浏览器缓存似乎是技术含量很低且麻烦的事情。

We are aware of the ?ver=xxx workaround, but we use RequireJS so it's not easy to apply such hack. 我们知道?ver=xxx解决方法,但是我们使用RequireJS,因此应用这种技巧并不容易。

Would HTTP cache control work? HTTP缓存控制会起作用吗? However, we noticed IIS does not pick up the JS file changes right away and the HTTP header (last modified) does not reflect the latest changes. 但是,我们注意到IIS不会立即接收JS文件的更改,并且HTTP标头(最近修改)没有反映最新的更改。

Would ETag work better? ETag会更好吗? Is it better or worse then last modified on IIS? 比IIS上一次修改好还是坏?

Any other solutions? 还有其他解决方案吗? Thanks 谢谢

RequireJS has a cache busting property that you can use -: RequireJS具有可以使用的缓存清除属性 -:

require.config({
    urlArgs: "bust=" + (new Date()).getTime()
});

Edit -: However, as Ian pointed out below, in their documents it is recommended not to use it this way for production code. 编辑-:但是,正如Ian在下面指出的那样,建议在他们的文档中不要将这种方式用于生产代码。

Everytime you push a new commit to production maybe you can instead add a specific version number. 每次您将新的提交提交到生产环境时,您都可以添加特定的版本号。

require.config({
        urlArgs: "ver=1.1.1"
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM