Improve service worker handling for DEV mode and cache updates
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const CACHE_NAME = 'lonc-shell-v1';
|
||||
const CACHE_NAME = 'lonc-shell-v2';
|
||||
const APP_SHELL = ['/', '/index.html', '/manifest.webmanifest', '/offline.html', '/icons/icon.svg', '/icons/icon-mask.svg'];
|
||||
|
||||
self.addEventListener('install', (event) => {
|
||||
@@ -40,6 +40,26 @@ self.addEventListener('fetch', (event) => {
|
||||
return;
|
||||
}
|
||||
|
||||
const destination = event.request.destination;
|
||||
if (
|
||||
destination === 'script' ||
|
||||
destination === 'style' ||
|
||||
destination === 'worker' ||
|
||||
requestUrl.pathname.endsWith('.js') ||
|
||||
requestUrl.pathname.endsWith('.css')
|
||||
) {
|
||||
event.respondWith(
|
||||
fetch(event.request)
|
||||
.then((networkResponse) => {
|
||||
const clone = networkResponse.clone();
|
||||
caches.open(CACHE_NAME).then((cache) => cache.put(event.request, clone));
|
||||
return networkResponse;
|
||||
})
|
||||
.catch(() => caches.match(event.request)),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
event.respondWith(
|
||||
caches.match(event.request).then((response) => {
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user