正在玩渐进式网络应用程序。我试图让网络应用安装横幅工作,但我一直收到 service worker does not successfully serve the manifest's start_url
在我使用 Lighthouse 调试之后(下图)。目前我正在使用 azure 托管我的网站。
新:
我检查了我所有的缓存、start_url 以及我的服务人员,以查看所有内容是否匹配。但它仍然给我同样的错误。
我不确定是不是我的 start_url
或我的service-worker
问题。下面是我的代码。manifest.json
{
"short_name": "MY EXPERTS",
"name": "MYEXPERT",
"icons": [
{
"src": "Images/petronas_logo_192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "Images/petronas_logo_192.png",
"type": "image/png",
"sizes": "512x512"
}
],
"background_color": "#FFFFFF",
"theme_color": "#67BCFF",
"display": "standalone",
"start_url": "/Home/Index"
}
AddServiceWorker.js
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js').
then(function (registration) {
// Registration was successful``
console.log('ServiceWorker registration successful with scope: ',
registration.scope);
}).catch(function (err) {
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
}
service-worker.js
self.addEventListener('install', e => {
e.waitUntil(
caches.open('airhorner').then(cache => {
return cache.addAll([
'/',
'/?utm_source=homescreen',
'/Home/About',
'/Home/Index',
'/Home/Contact'
])
.then(() => self.skipWaiting());
})
)
});
self.addEventListener('activate', event => {
event.waitUntil(self.clients.claim());
});
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request).then(response => {
return response || fetch(event.request);
})
);
});
我的浏览器缓存:
最佳答案
来自 Register A service worker ,
If we register the service worker file at
/example/sw.js
, then the service worker would only seefetch
events for pages whose URL starts with/example/
(i.e./example/page1/
,/example/page2/
).
内联显示的错误并在此 documentation 中给出,请检查以下内容:
- Define a
start_url
property in yourmanifest.json
file.- Ensure that your service worker properly caches a resource that matches the value of
start_url
.
另外,请查看 tutorial看看它是否会帮助你。
关于javascript - 渐进式 Web 应用程序 - Service Worker 不提供 start_URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46726966/