fix: refresh cached app shell after deployments
ci / docker (push) Successful in 3m48s

This commit is contained in:
2026-09-05 17:04:46 +08:00
parent 9e378b1fbf
commit 8e24b8f07b
2 changed files with 12 additions and 4 deletions
+8 -3
View File
@@ -1,5 +1,5 @@
const CACHE = 'dodo-shell-v2'
const SHELL = ['/', '/manifest.json', '/icon-192.png', '/icon-512.png', '/apple-touch-icon.png']
const CACHE = 'dodo-shell-v3'
const SHELL = ['/manifest.json', '/icon-192.png', '/icon-512.png', '/apple-touch-icon.png']
self.addEventListener('install', (event) => {
self.skipWaiting()
event.waitUntil(caches.open(CACHE).then((cache) => cache.addAll(SHELL)))
@@ -11,11 +11,16 @@ self.addEventListener('fetch', (event) => {
const url = new URL(event.request.url)
if (url.pathname.startsWith('/api/')) return
if (event.request.method !== 'GET') return
const isNavigation = event.request.mode === 'navigate'
if (isNavigation) {
event.respondWith(fetch(event.request).catch(() => caches.match('/offline.html')))
return
}
event.respondWith(
caches.match(event.request).then((cached) => cached || fetch(event.request).then((response) => {
const copy = response.clone()
caches.open(CACHE).then((cache) => cache.put(event.request, copy))
return response
}).catch(() => caches.match('/'))),
})),
)
})