Service Worker 与 HTML5 缓存:要么

Service worker vs HTML5 Cache: either or

我需要一个网站来缓存数据。并设置了 Cache Storage(通过 Service Worker)和 Application Cache(通过 html 清单属性)。他们工作。

我的问题是:如果浏览器支持服务器工作者,如何忽略应用程序缓存?

互联网上的一些阅读建议如果缓存存储有效,Chrome 将忽略应用程序缓存。我觉得没有。 Chrome 63 Mac OS X.

一个选项似乎是根据浏览器和 OS 类型在服务器上创建动态页面(保留或不保留清单属性)。有没有更好的办法?谢谢

服务工作者激活后,它控制的客户端页面的任何现有应用程序缓存实例将自动取消关联。此行为在 service worker specification:

中激活算法的第 6 步中进行了描述

For each service worker client client whose creation URL matches registration’s scope url:

  1. If client is a window client, unassociate client’s responsible document from its application cache, if it has one.

  2. Else if client is a shared worker client, unassociate client’s global object from its application cache, if it has one.

如果您没有看到该行为,并且您确定服务工作者已激活并控制了给定客户端 window,那么这听起来像是浏览器实现中的错误。您应该在相应浏览器的错误跟踪器上跟进有关重现步骤的详细信息。