我正在尝试为我的个人网站创建一个渐进式的web应用程序。PWA能够在离线时访问缓存(通过服务工作者),在Chrome Desktop、Firefox或Firefox移动设备上没有问题。当我在离线的时候尝试在Chrome Mobile上打开相同的PWA时,我得到了错误“无法连接到站点”。如果我在关闭网络(打开PWA )后尝试重新加载PWA,它可以在Chrome Desktop、Firefox和Firefox移动设备上使用缓存,但在Chrome mobile上我收到错误消息"ERR_FAILED“。
我已经看过了不同的问题,并尝试了答案和评论所说的尝试。但我的PWA现在可以在Chrome Mobile上离线工作了。我还尝试将" start_url“设置为"”,因为https://developers.google.com/web/fundamentals/web-app-manifest/说“start_url是相对于在scope属性中定义的路径”,但这样做会将起始页设置为清单。将"start_url“设置为"/”将删除用于安装应用程序的弹出窗口。我还尝试将"/“和"”添加到FILES_TO_CACHE数组中,但仍然出现错误。
Manifest.json:
{
"name": "Webnote",
"short_name": "Webnote",
"icons": [
{
"src": "/webnote/webnote192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "/webnote/webnote512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": "/webnote/",
"background_color": "#0217B3",
"display": "standalone",
"scope": "/webnote/",
"theme_color": "#333333"
}sw.js:
var CACHE_NAME = 'webnote-app-cache';
var FILES_TO_CACHE = [
'/webnote/'
];
self.addEventListener('install', function(event){
event.waitUntil(
caches.open(CACHE_NAME).then(function(cache) {
return cache.addAll(FILES_TO_CACHE);
})
);
self.skipWaiting();
});
self.addEventListener('fetch', function(event){
if (event.request.mode !== 'navigate') {
return;
}
event.respondWith(
fetch(event.request).catch(function(){
return caches.open(CACHE_NAME).then(function(cache){
return cache.match(event.request);
});
})
);
});发布于 2021-09-23 08:38:52
当我使用start_url时,它在我的笔记本电脑上起作用了,但在手机上就不行了:'/abcd/‘
使用start_url:‘’解决了我的问题
https://stackoverflow.com/questions/57780601
复制相似问题