简体   繁体   English

确保用户在更新后获得网站最新版本的正确方法

[英]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 其他一些信息

  • I can never replicate this issue locally (and by that I mean in debug, on our staging site or our production site) 我永远无法在本地复制此问题(这意味着在调试中,在我们的登台站点或生产站点上)
  • We use CloudFlare but purge the entire cache after release 我们使用CloudFlare,但在发布后清除整个缓存
  • We have a mechanism in JS that checks on page load or every 5 minutes to see if the version of our API has changed, and if so show up a "Please refresh your browser" message. 我们在JS中提供了一种机制,可以每5分钟检查一次页面加载,以查看我们的API版本是否已更改,如果更改了,请显示“请刷新浏览器”消息。 Clicking this runs window.location.reload(true); 单击此运行window.location.reload(true);
  • Our backend is IIS 我们的后端是IIS

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.

相关问题 确保用户获得最新的Javascript - Ensuring Users Get Latest Javascript 确保在回调后触发异步方法 - Ensuring an async method fires after a callback 我应该在HTML中添加什么来确保用户获得我的页面的最新版本,而不是旧版本? - What do I put in my HTML to ensure users get latest version of my page, not old version? 如何使用 JavaScript 将我们的网站更新到最新版本? 基本上是硬重新加载或清除缓存并重新加载 - How to update our website to latest version using JavaScript ? Basically Hard Reload or Clear cache and reload Heroku:将节点更新到最新版本 - Heroku: Update Node to latest version 如何将lodash更新到最新版本 - How to update lodash to the latest version 在网站上获取最新的Twitter帖子 - Get latest Twitter post on website JS:在循环中的push()未分配正确值之后,更新最新添加的元素的属性 - JS: Update an attribute of the latest added element after push() in a loop does not assign the correct value 如何在解析云代码迁移后更新到最新版本的Parse-SDK-JS - How to update to latest version of Parse-SDK-JS after parse migration of cloud code 嗨,我无法使CSS旋转动画正常工作吗? 使用最新版本。 更新:在Chrome上运行 - Hi, I can't get the CSS spinning animation to work? Using latest version. Update: running on Chrome
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM