服务人员:文件已在服务器上更新,但旧版本显示在浏览器中 [英] Service Worker: files are updated on the server but old version showing in browser

查看:341
本文介绍了服务人员:文件已在服务器上更新,但旧版本显示在浏览器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Google AppEngine上使用PouchDB构建静态应用.

I am building a static app with PouchDB on Google AppEngine.

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

如果我在隐身窗口中打开该网站,则会显示更新的版本(因此,我认为控制台中实际上不是错误).

我在app.yaml

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

I have migrated all traffic to the new version.

我已经清除了缓存,删除了cookie,检查了我的应用程序数据,所有内容.我什至重新安装了Chrome和Firefox.

I have cleared my cache, deleted cookies, checked my application data, everything. I even reinstalled Chrome and Firefox.

昨天我更新了Python版本和Google AppEngine启动器;该问题早于该更新.

I updated my Python version and my Google AppEngine Launcher yesterday; the problem pre-dated that update.

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

Also: just discovered that if I go to the URL of the updated version http://4.[app-id].appspot.com, it displays the correct, updated version.

这是在Chrome,Firefox和Edge中发生的.

This is happening in Chrome, Firefox, and Edge.

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

probably should have mentioned that my site uses Service Workers and IndexedDB. I assume my service workers are caching the previous version, but I would have thought that Ctrl + F5 would clear the cache and show the new version.

推荐答案

我认为这必须是服务人员在缓存页面(毕竟,这是他们应该做的).但是,当您进行开发时,这确实很烦人.

I think it must be the Service Workers caching the pages (which is, after all, what they are supposed to do). This is actually really annoying when you are developing though.

一个名叫.

A guy called Rich Harris has documented this behaviour and some workarounds on a Github Gist.

重新加载页面的行为不符合您的预期

如果对服务人员进行了更改,请重新加载页面 不会杀死旧版本并激活新版本(它会检测到更改 通过每次请求服务工作者文件并比较旧文件 和新的逐字节),这让您有些困惑 您的更改尚未生效.这是因为旧窗口是 从来没有真正关闭过,这意味着永远没有时间将它们交换出去– 您需要完全杀死该标签,然后重新打开它.

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.

或者您可以让浏览器通过转到 devtools中的应用程序"标签(在Canary中,尚不稳定) 进入服务工作者"部分,然后选中重新加载时更新".

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.

UPDATE (13 Nov 2017): This functionality is now available in Chrome, so you don't even need to download Canary.

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

And here's which bits of the application cache to clear:

这篇关于服务人员:文件已在服务器上更新,但旧版本显示在浏览器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆