五件套徒手健身打卡应用:FastAPI+Vue3+PWA
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
const CACHE = 'workout-five-v1'
|
||||
const ASSETS = ['/', '/manifest.json', '/icon-192.png', '/icon-512.png', '/apple-touch-icon.png']
|
||||
|
||||
self.addEventListener('install', (e) => {
|
||||
e.waitUntil(caches.open(CACHE).then((c) => c.addAll(ASSETS)).then(() => self.skipWaiting()))
|
||||
})
|
||||
|
||||
self.addEventListener('activate', (e) => {
|
||||
e.waitUntil(
|
||||
caches.keys().then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)))).then(() => self.clients.claim())
|
||||
)
|
||||
})
|
||||
|
||||
self.addEventListener('fetch', (e) => {
|
||||
const url = new URL(e.request.url)
|
||||
if (e.request.method !== 'GET' || url.pathname.startsWith('/api/')) {
|
||||
return // API 走网络
|
||||
}
|
||||
e.respondWith(
|
||||
caches.match(e.request).then((hit) => hit || fetch(e.request).then((resp) => {
|
||||
const clone = resp.clone()
|
||||
caches.open(CACHE).then((c) => c.put(e.request, clone))
|
||||
return resp
|
||||
}))
|
||||
)
|
||||
})
|
||||
Reference in New Issue
Block a user