【问题标题】:Since Chrome 85 cache.addAll of Service Worker does not cache with Cache-Control to "no-store"由于 Chrome 85 cache.addAll of Service Worker 不使用 Cache-Control 缓存到“no-store”
【发布时间】:2020-09-02 16:46:31
【问题描述】:

如果您在 Service Worker 中使用 cache.addAllcache.add,请注意您在 .htaccess 或其他地方的 Cache-Control 配置。

在新版本的 Chrome 85 中,使用 no-store 值作为 Cache-Control 会阻止 Service Worker 缓存文件。

此外,Service Worker 安装失败,您的网站/应用程序可能会受到威胁。

【问题讨论】:

    标签: google-chrome service-worker browser-cache cache-control


    【解决方案1】:

    编辑:这可能是由于 Chrome bug 已解决。

    这不是预期的行为。我在Service Worker Specification 中没有看到任何提及“no-store”的内容,我在ChromeStatus 中也没有看到任何表明已进行更改的内容。

    我也无法在 Mac 版 Chrome 85.0.4183.83 上重现该问题。

    例如,在 JS 控制台中运行以下代码会导致成功添加缓存:

    cache = await caches.open('test-cache');
    await cache.addAll([
      'https://httpbin.org/response-headers?Cache-Control=no-cache, no-store, must-revalidate&X-Test=1',
      'https://httpbin.org/response-headers?Cache-Control=no-cache, no-store, must-revalidate&X-Test=2',
      'https://httpbin.org/response-headers?Cache-Control=no-cache, no-store, must-revalidate&X-Test=3',
      'https://httpbin.org/response-headers?Cache-Control=no-cache, no-store, must-revalidate&X-Test=4',
      'https://httpbin.org/response-headers?Cache-Control=no-cache, no-store, must-revalidate&X-Test=5',
    ]);
    

    是什么让你认为它不起作用,你能指出问题的重现吗?

    【讨论】:

    • 感谢 Jeff 的回复。尝试在 .htaccess 中使用例如这一行: Header set Cache-Control "no-cache, no-store, must-revalidate"
    • 同时使用单个文件缓存也没有显示问题。尝试使用至少包含 5 个元素的数组,并使用该数组的 cache.addAll(array)。
    • 我刚刚更新了示例,使用 Cache-Control 响应标头一次添加 5 个条目,但仍然无法重现失败。
    • 这可能是由于安装服务工作人员受到限制。这是我上周启用的一项功能,但会导致 cache.addAll() 出现问题。从今天开始,我已经禁用了它。下次重新启动浏览器时它应该会生效。见crbug.com/1124632
    • 仅供参考,在解决了 cache.addAll() 的问题后,我在安装事件中重新启用了限制网络请求。根据试验和测量,我认为这不会再次引起类似这个问题的问题,但我想在这里提一下。见:groups.google.com/a/chromium.org/g/blink-dev/c/KlgQ-j0Wx0U/m/…
    猜你喜欢
    • 2019-07-09
    • 2022-11-17
    • 2022-12-09
    • 1970-01-01
    • 2022-01-24
    • 2011-11-26
    • 1970-01-01
    • 2020-12-19
    • 2014-01-16
    相关资源
    最近更新 更多