首页 > 解决方案 > 当旧站点不再可访问时,如何清除浏览器缓存的服务人员?

问题描述

我为客户建立了一个新站点,并接管了他们的域管理和使用新的主机。以前的站点和托管已被完全删除。

我遇到了一个我不知道如何解决的主要问题。之前的开发人员使用 service worker 来缓存和加载之前的站点。问题是之前访问过该站点的用户一直看到旧站点,因为它都是从缓存加载的。这个旧站点甚至不再存在,所以我无法添加任何 javascript 来从他们的浏览器中删除服务工作者,除非他们访问新站点。

有没有人遇到过这个问题并知道解决方法?请注意,要求用户从浏览器中删除服务工作者是行不通的。

标签: cachingdnsservice-workerbrowser-cache

解决方案


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.

Updating the service worker


推荐阅读