|
|
@@ -1,9 +1,10 @@
|
|
|
const CACHE_NAME = 'torqvoice-offline-v1'
|
|
|
const OFFLINE_URL = '/offline.html'
|
|
|
+const OFFLINE_ASSETS = [OFFLINE_URL, '/icons/icon-192.png']
|
|
|
|
|
|
self.addEventListener('install', (e) => {
|
|
|
e.waitUntil(
|
|
|
- caches.open(CACHE_NAME).then((cache) => cache.addAll([OFFLINE_URL, '/icons/icon-192.png']))
|
|
|
+ caches.open(CACHE_NAME).then((cache) => cache.addAll(OFFLINE_ASSETS))
|
|
|
)
|
|
|
self.skipWaiting()
|
|
|
})
|
|
|
@@ -18,8 +19,16 @@ self.addEventListener('activate', (e) => {
|
|
|
})
|
|
|
|
|
|
self.addEventListener('fetch', (e) => {
|
|
|
- if (e.request.mode !== 'navigate') return
|
|
|
- e.respondWith(
|
|
|
- fetch(e.request).catch(() => caches.match(OFFLINE_URL))
|
|
|
- )
|
|
|
+ if (e.request.mode === 'navigate') {
|
|
|
+ e.respondWith(
|
|
|
+ fetch(e.request).catch(() => caches.match(OFFLINE_URL))
|
|
|
+ )
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (OFFLINE_ASSETS.includes(new URL(e.request.url).pathname)) {
|
|
|
+ e.respondWith(
|
|
|
+ fetch(e.request).catch(() => caches.match(e.request))
|
|
|
+ )
|
|
|
+ }
|
|
|
})
|