修复:更新离线缓存与登录导航策略
This commit is contained in:
parent
8d3f5e769e
commit
efdc78d7b1
34
serviceworker.js
vendored
34
serviceworker.js
vendored
@ -1,22 +1,20 @@
|
||||
var staticCacheName = "pwa-v" + new Date().getTime();
|
||||
var staticCacheName = "pwa-v2";
|
||||
var filesToCache = [
|
||||
'public/img/pwa/icon-192x192.png',
|
||||
'public/img/pwa/icon-512x512.png'
|
||||
'/public/img/pwa/icon-192x192.png',
|
||||
'/public/img/pwa/icon-512x512.png'
|
||||
];
|
||||
|
||||
/*
|
||||
// Cache on install
|
||||
self.addEventListener("install", event => {
|
||||
this.skipWaiting();
|
||||
event.waitUntil(
|
||||
caches.open(staticCacheName)
|
||||
.then(cache => {
|
||||
return cache.addAll(filesToCache);
|
||||
})
|
||||
.then(() => self.skipWaiting())
|
||||
)
|
||||
});
|
||||
*/
|
||||
/*
|
||||
|
||||
// Clear cache on activate
|
||||
self.addEventListener('activate', event => {
|
||||
event.waitUntil(
|
||||
@ -27,19 +25,29 @@ self.addEventListener('activate', event => {
|
||||
.filter(cacheName => (cacheName !== staticCacheName))
|
||||
.map(cacheName => caches.delete(cacheName))
|
||||
);
|
||||
})
|
||||
}).then(() => self.clients.claim())
|
||||
);
|
||||
});*/
|
||||
});
|
||||
|
||||
// Serve from Cache
|
||||
// Navigation must prefer the network so cached redirects cannot mask auth state.
|
||||
self.addEventListener("fetch", event => {
|
||||
if (event.request.method !== 'GET') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.request.mode === 'navigate') {
|
||||
event.respondWith(
|
||||
fetch(event.request)
|
||||
.catch(() => caches.match(event.request))
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
event.respondWith(
|
||||
caches.match(event.request)
|
||||
.then(response => {
|
||||
return response || fetch(event.request);
|
||||
})
|
||||
.catch(() => {
|
||||
return caches.match('offline');
|
||||
})
|
||||
)
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user