我正在尝试为一个小的静态站点设置一个简单的Service Worker,但是我得到了一个service worker控制台错误:
sw.js:59 Uncaught TypeError: workbox.expiration.CacheableResponsePlugin is not a constructor
这是在new workbox.expiration.CacheableResponsePlugin行
任何关于如何解决这个问题的建议都将不胜感激。
workbox.routing.registerRoute(
/\.(?:html)$/,
new workbox.strategies.NetworkFirst({
cacheName: 'html-cache',
plugins: [
new workbox.expiration.CacheableResponsePlugin({
statuses: [0, 200],
}),
new workbox.expiration.ExpirationPlugin({
maxEntries: 50,
maxAgeSeconds: 5 * 60,
})
]
})
)发布于 2020-06-07 05:33:56
我从workbox v4迁移到v5时遇到了同样的问题。
在代码中,
new workbox.expiration.CacheableResponsePlugin应该是
new workbox.cacheableResponse.CacheableResponsePlugin发布于 2020-11-27 09:21:56
Example:
workbox.routing.registerRoute(new RegExp('https://assets.abcd.com/.*\.*'),
new workbox.strategies.CacheFirst({
cacheName: 'assets',
plugins: [
new workbox.cacheableResponse.Plugin({
statuses: [0, 200, 206] // 206 Partial Code.
}),
new workbox.rangeRequests.Plugin()
]}))发布于 2021-07-14 02:04:51
它的
new workbox.cacheableResponse.Plugin现在
https://stackoverflow.com/questions/60310455
复制相似问题