无法为jekyll支持的项目网站设置服务工作者,灯塔拒绝start_url
值并发出错误Unable to fetch start URL via service worker
app->manifest输出显示了根/
尝试./index.html
- 结果相同。有没有办法通过审核?
的manifest.json:
{
"name": "outcast",
"short_name": "outcast",
"icons": [
{
"src": "/assets/images/splsh192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "/assets/images/splsh512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"lang": "en-US",
"display": "standalone",
"background_color": "#131313",
"theme_color": "#f62e1a",
"start_url": "/",
"serviceworker": {
"src": "sw.js",
"scope": "/",
"update_via_cache": "none"
}
}
答案 0 :(得分:2)
使用官方指南中的代码替换fetch
中的sw.js
处理程序修复了该问题。仍在调试未定义的缓存
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request)
.then(function(response) {
// Cache hit - return response
if (response) {
return response;
}
return fetch(event.request);
}
)
);
});
答案 1 :(得分:0)
您可以尝试这种方式。我有一个类似的问题:
self.addEventListener("fetch", function(event) {
event.respondWith(
fetch(event.request).catch(function(error) {
console.log(
"[Service Worker] Network request Failed. Serving content from cache: " +
error
);
//Check to see if you have it in the cache
//Return response
//If not in the cache, then return error page
return caches
.open(
"https://your.website"
)
.then(function(cache) {
return cache.match(event.request).then(function(matching) {
var report =
!matching || matching.status == 404
? Promise.reject("no-match")
: matching;
return report;
});
});
})
);
});