[英]Correct method for ensuring users get the latest version of a website after an update
Everytime I deploy an update to our web application customers ring in with issues where their browser hasnt picked up that index.html has changed and since the name of the .js file has changed they run into errors. 每当我向我们的Web应用程序部署更新时,客户都会遇到问题,即他们的浏览器尚未获取到index.html已更改的问题,并且由于.js文件的名称已更改,因此他们会遇到错误。 Presumably because their index.html still points to the old javascript file which no longer exists. 大概是因为它们的index.html仍指向不再存在的旧javascript文件。
What is the correct way to ensure that users always get the latest version when the system is updated. 确保系统更新时用户始终获得最新版本的正确方法是什么?
We have a HTML5 + AngularJS web application. 我们有一个HTML5 + AngularJS Web应用程序。 It uses WebPack to bundle the vendor and app javascript into two js files. 它使用WebPack将供应商和应用javascript捆绑为两个js文件。 The files contain a hashname to ensure they are different once released. 这些文件包含一个哈希名称,以确保它们在发布后有所不同。
Some other information 其他一些信息
window.location.reload(true);
单击此运行window.location.reload(true);
If you need users to pick up the latest index.html
when they load your site immediately after you've updated the file, make index.html
non-cacheable. 如果您需要用户在更新文件后立即加载您的网站时选择最新的index.html
,请将index.html
不可缓存。 That will mean the browser, CloudFlare, and any intermediate proxies aren't allowed to cache it, and that one file will always be served from your canonical server. 这将意味着不允许浏览器,CloudFlare和任何中间代理对其进行缓存,并且始终会从您的规范服务器提供一个文件。
Naturally, that has a traffic and latency impact (for you and them), but if that's really your requirement, I don't see any other option. 当然,这会对流量和延迟产生影响(对于您和他们),但是如果这确实是您的要求,那么我看不到任何其他选择。
There are spins on this. 有旋转。 It might not be index.html
itself that isn't cacheable, you could insert another resource (a tiny JavaScript file that writes out the correct script
tags) if index.html
is really big and it's important to cache it, etc. But if you need the change picked up immediately, you'll need a non-cacheable resource that identifies the change. 可能不是index.html
本身不能缓存,如果index.html
很大并且缓存它很重要,则可以插入另一个资源(写有正确script
标记的小JavaScript文件)。但是,如果您需要立即获取更改,您将需要标识该更改的不可缓存资源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.