【发布时间】:2021-04-29 20:10:56
【问题描述】:
我正在尝试在我的 runtimeCaching 中设置资产的过期时间。作为一个例子,我有这个:
{
// https://code.jquery.com/jquery-3.5.1.min.js
urlPattern: /^https:\/\/code\.jquery\.com\/jquery-3\.5\.1.*/,
handler: 'CacheFirst',
options: {
cacheName: 'external-assets',
cacheableResponse: {
statuses: [0, 200]
},
cacheExpiration: {
maxAgeSeconds: 60 * 60 * 24 * 14, // 2 Week
maxEntries: 1
}
}
},
当我尝试通过 NPM 脚本运行 generateSW() 时,在控制台中,我得到:
> ispot@0.1.0 sw
> node sw_build.js
[Error [ValidationError]: "runtimeCaching[0].options.cacheExpiration" is not allowed] {
_original: {
swDest: './public/service-worker.js',
skipWaiting: true,
clientsClaim: true,
cleanupOutdatedCaches: true,
mode: 'development',
runtimeCaching: [ [Object], [Object], [Object], [Object], [Object], [Object] ]
},
details: [
{
message: '"runtimeCaching[0].options.cacheExpiration" is not allowed',
path: [Array],
type: 'object.unknown',
context: [Object]
}
]
}
在 Workbox 的网站上很难找到有关如何为 generateSW() 进行设置的文档。
【问题讨论】:
标签: progressive-web-apps service-worker workbox