Javascript Service Worker在大多数移动浏览器中都不起作用
我有一个静态站点,上面有服务人员,它托管在GitLab页面上,在我的笔记本电脑上可以完美地脱机工作,但有时几乎在任何移动浏览器中都不能脱机工作(在Opera Mini中工作,但在mobile Chrome中不工作)。所以我想弄清楚它到底出了什么问题 我的服务人员注册脚本,该脚本在我的站点根目录中的index.html处调用:Javascript Service Worker在大多数移动浏览器中都不起作用,javascript,service-worker,Javascript,Service Worker,我有一个静态站点,上面有服务人员,它托管在GitLab页面上,在我的笔记本电脑上可以完美地脱机工作,但有时几乎在任何移动浏览器中都不能脱机工作(在Opera Mini中工作,但在mobile Chrome中不工作)。所以我想弄清楚它到底出了什么问题 我的服务人员注册脚本,该脚本在我的站点根目录中的index.html处调用: if ('serviceWorker' in navigator) { window.addEventListener('load', function() {
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('./serviceWorker.js').then(function (registration) {
// Registration was successful
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}, function (err) {
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
});
}
我的服务人员自己:
let cache_v1 = 'cache_v1';
self.addEventListener('install', function(event) {
event.waitUntil(
caches.open(cache_v1)
.then(cache => cache.addAll(
[
'./',
'./index.html',
'./favicon.png',
'./dist/bundle.js',
'./dist/style.css',
'./src/icons/soyuz_apollo192.png',
'./src/icons/soyuz_apollo_apple_icon.png',
'./src/img/asia.png',
'./src/img/pustota.jpeg',
'./src/img/zima-min.jpg'
]
))
)
})
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request)
.then(matching => {
return matching || fetch(event.request)
})
)
})
告诉我,如果你还需要知道什么来帮助你看一看,我使用最新的Chrome浏览器(目前是71)它了解服务人员Chrome Android 71?Chrome 71 for iOS我相信Chrome浏览器只在iOS中包装webkit,所以为了确保兼容性,我会使用mobile safari专栏。但即使如此,看起来它应该有基本的支持。。。