使用 workbox-webpack-plugin 时,预缓存资产使用什么工作箱策略?
What workbox strategy is used for precached assets when using workbox-webpack-plugin?
我正在尝试了解工作箱和 service-workers。
使用 workbox-webpack-plugin 和 GenerateSW 模式时,用于预缓存资产的工作箱策略是什么? IE。 cacheFirst、staleWhileRevalidate 等。因为似乎我没有为预缓存资产设置 route/strategy 以便 service-worker 更新这些资产的缓存。那么这些的默认处理程序是什么?
其次,来自服务器响应的Cache-Control headers如何在刷新资产的工作箱策略中发挥作用?如果有的话。
回答关于根 /index.html 资产的问题对我最有帮助。
谢谢。
workbox-webpack-plugin
生成一个调用 workbox.precaching.precacheAndRoute([...])
的服务工作者,其中包含 URL 的数组(以及每个 URL 的可选修订信息)。
对 precacheAndRoute()
的调用做了两件事:
Precaches 提供的所有 URLs。
自动为您创建一个 fetch
处理程序,它将检查传入的请求以查看它是否与预缓存的 URL 匹配,如果是,则以有效的缓存响应-第一个策略。 (这是 和 route 部分。)匹配时的 code that gets invoked 不是字面上的 workbox.strategies.cacheFirst()
,而是大致等价的。
automatically avoid the browser's HTTP cache if there is out-of-band revision information provided for a given entry in the precache manifest—it uses that as a signal that the contents of the URL might change over time. The docs workbox-precaching
模块的 Workbox 将更清楚地说明正在发生的事情。
我正在尝试了解工作箱和 service-workers。
使用 workbox-webpack-plugin 和 GenerateSW 模式时,用于预缓存资产的工作箱策略是什么? IE。 cacheFirst、staleWhileRevalidate 等。因为似乎我没有为预缓存资产设置 route/strategy 以便 service-worker 更新这些资产的缓存。那么这些的默认处理程序是什么?
其次,来自服务器响应的Cache-Control headers如何在刷新资产的工作箱策略中发挥作用?如果有的话。
回答关于根 /index.html 资产的问题对我最有帮助。
谢谢。
workbox-webpack-plugin
生成一个调用 workbox.precaching.precacheAndRoute([...])
的服务工作者,其中包含 URL 的数组(以及每个 URL 的可选修订信息)。
对 precacheAndRoute()
的调用做了两件事:
Precaches 提供的所有 URLs。
自动为您创建一个
fetch
处理程序,它将检查传入的请求以查看它是否与预缓存的 URL 匹配,如果是,则以有效的缓存响应-第一个策略。 (这是 和 route 部分。)匹配时的 code that gets invoked 不是字面上的workbox.strategies.cacheFirst()
,而是大致等价的。
automatically avoid the browser's HTTP cache if there is out-of-band revision information provided for a given entry in the precache manifest—it uses that as a signal that the contents of the URL might change over time. The docs workbox-precaching
模块的 Workbox 将更清楚地说明正在发生的事情。