service-worker - Workbox 预缓存:如果某些 URL 失败,不要失败
问题描述
我正在尝试使用带有工作箱和 gulp 的下一个代码生成 SW
gulp.task('generate-service-worker', () => {
return workbox.generateSW({
globDirectory: root,
globPatterns: [
'**/!(*.map|*.html|*.txt|*.orig)'
],
swDest: `${root}/javascripts/sw/sw.js`,
clientsClaim: true,
skipWaiting: true
}).then(({warnings, count, size}) => {
//In case there are any warnings from workbox-build, log them.
for (const warning of warnings) {
console.warn(warning);
}
console.info(`Service worker generation completed.Count: ${count}, size: ${size}`);
}).catch((error) => {
console.warn('Service worker generation failed:', error);
});
});
生成服务工作者。但是,如果在安装期间其中一个 URL 失败,则整个安装过程将失败,并且新的 service worker 不会被激活。是否可以忽略获取失败并继续使用剩余 URL 的预缓存?
解决方案
推荐阅读
- javascript - 为什么 PHP / Materialize 网站在本地完美呈现时没有在服务器上呈现?
- excel - 根据区间值提取时隙
- excel - VBA - 单击饼图的不同部分以运行不同的宏
- javascript - 防止按钮上的输入键按下 - Vue
- varnish - 当清漆中有多个设置 cookie 请求时,如何获取设置的 cookie 值?
- excel-formula - 在与两列表中的单词匹配的列中查找关键字并返回第二列中的值
- reactjs - 在同一台服务器上托管 Django 和 React?
- c# - 如何将值从子组件(RenderFragment)传递到 C# Blazor 中的父页面?
- sql - PowerApps:UpdateIf 只更新前 100 条记录(SQL-Datasource)
- api - 无法访问 Maximo API 的文档?