Service Worker:文件在服务器上更新,但旧版本显示在浏览器中

Service Worker: files are updated on the server but old version showing in browser

我正在 Google AppEngine 上使用 PouchDB 构建静态应用程序。

当我在浏览器中打开网站时 window,它显示的是我几个小时前上传的版本。

如果我以隐身模式打开网站 window,则会显示更新版本(因此我认为这实际上不是控制台中的错误)。

我在app.yaml

中输入了新的版本号

我已将所有流量迁移到新版本。

我已经清除了我的缓存,删除了 cookie,检查了我的应用程序数据,一切。我什至重新安装了 Chrome 和 Firefox。

我昨天更新了 Python 版本和 Google AppEngine Launcher;该问题早于该更新。

另外:刚刚发现如果我去更新版本的URL http://4.[app-id].appspot.com,它显示正确的更新版本。

这发生在 Chrome、Firefox 和 Edge 中。

编辑:可能应该提到我的站点使用 Service Workers 和 IndexedDB。我假设我的服务人员正在缓存以前的版本,但我认为 Ctrl + F5 会清除缓存并显示新版本。

我想一定是 Service Worker 缓存了页面(毕竟这是他们应该做的)。不过,这在您开发时确实很烦人。

一个叫 Rich Harris has documented this behaviour and some workarounds on a Github Gist 的人。

Reloading the page doesn't behave as you'd expect

If you make a change to your service worker, then reloading the page won't kill the old one and activate the new one (it detects the change by requesting the service worker file each time and comparing the old and the new byte-for-byte), leaving you somewhat confused as to why your changes haven't taken effect. This is because the old window is never actually closed, meaning there's never a time to swap them out – you need to kill the tab completely then reopen it.

Or you can have the browser do that for you by going to the Application tab in devtools (in Canary, not stable Chrome yet), going to the Service Workers section, and checking 'Update on reload'.

更新(2017 年 11 月 13 日):此功能现已在 Chrome 中可用,因此您甚至不需要下载 Canary。

下面是要清除的应用程序缓存的哪些位: