caching - 当旧站点不再可访问时,如何清除浏览器缓存的服务人员?
问题描述
我为客户建立了一个新站点,并接管了他们的域管理和使用新的主机。以前的站点和托管已被完全删除。
我遇到了一个我不知道如何解决的主要问题。之前的开发人员使用 service worker 来缓存和加载之前的站点。问题是之前访问过该站点的用户一直看到旧站点,因为它都是从缓存加载的。这个旧站点甚至不再存在,所以我无法添加任何 javascript 来从他们的浏览器中删除服务工作者,除非他们访问新站点。
有没有人遇到过这个问题并知道解决方法?请注意,要求用户从浏览器中删除服务工作者是行不通的。
解决方案
You can use cache busting to achieve the outcome. As per Keycdn
Cache busting solves the browser caching issue by using a unique file version identifier to tell the browser that a new version of the file is available. Therefore the browser doesn’t retrieve the old file from cache but rather makes a request to the origin server for the new file.
In case you want to update the service worker itself, you should know, for a service worker an update is triggered if any of the following happens:
- A navigation to an in-scope page.
- A functional events such as push and sync, unless there's been an update check within the previous 24 hours.
- Calling .register() only if the service worker URL has changed. However, you should avoid changing the worker URL.
推荐阅读
- ruby-on-rails - 如何为 ruby 2.7.1 解决 AWS Elastic Beanstalk 上的 Rail 6 部署错误
- installation - 使用 cargo 安装 deno 时“找不到名为 `map_or` 的方法”
- r - sh 权限在exams2pdf 中被拒绝
- django - Heroku 不断更改我的 heroku-redis 插件的 url
- random-forest - 如何仅获得概率大于 x 的预测
- keras - Keras-tuner Hyperband 仅运行 2 个 epoch
- sql - 性能调优 SparkSQL 查询(带反连接)
- java - JAVA:图形创建
- javac - 为什么我只能在cmd中以管理员身份运行javac?
- json - 如何在 Delphi 中解析这种类型的 JSON 数据?