workbox - workbox.cacheableResponse.Plugin 不抛出构造函数错误,v6.0.2
问题描述
importScripts('https://storage.googleapis.com/workbox-cdn/releases/6.0.2/workbox-sw.js');
workbox.routing.registerRoute(
({ url, request }) => {
if (url.host === self.location.host && request.destination !== 'document') {
return true;
}
},
new workbox.strategies.CacheFirst({
cacheName: CACHE_KEY,
plugins: [
new workbox.cacheableResponse.Plugin({
statuses: [0, 200]
})
]
})
);
抛出错误: Uncaught TypeError: workbox.cacheableResponse.Plugin is not a constructor。
但是如果我使用new workbox.cacheableResponse.CacheableResponse({statuses: [0, 200]}),没有错误,但是插件仍然没有效果。(即使将可缓存状态设置为 [0,200],不透明响应也不会存储到缓存中)
解决方案
新的 workbox.cacheableResponse.Plugin 是 v4.0.3 的 api。我使用v6.0.2,但不幸的是@types/cacheableResponse 的最新版本是v4.0.3。
正确的 api 是 v6.0.2 的新 workbox.cacheableResponse.CacheableResponsePlugin
推荐阅读
- ios - 屏幕共享因 iPAD 中的 (null) 而停止
- css - 如何在 Shopify 的产品页面上制作全宽图像(如横幅)?
- reactjs - 在 Reactjs 中返回多个下拉值
- python - 在子类中仅获取一个 href
- c++ - C 预处理器在多大程度上考虑整数文字后缀?
- javascript - 链接 Jquery 以创建活动表
- html - 带有填充的弹性项目溢出容器
- javascript - 获取对象中连续重复属性的最后一个值
- python - 尽管我使用相同的输入,为什么 sm.OLS 和 sklearn.linear_model 会得到不同的结果?
- flutter - 侧边菜单项中的下拉按钮