added button
This commit is contained in:
31
public/sw.js
Normal file
31
public/sw.js
Normal file
@@ -0,0 +1,31 @@
|
||||
const CACHE = 'gj-v1'
|
||||
|
||||
self.addEventListener('install', (e) => {
|
||||
e.waitUntil(
|
||||
caches.open(CACHE).then((cache) =>
|
||||
cache.addAll(['/', '/manifest.json', '/icon.svg'])
|
||||
)
|
||||
)
|
||||
self.skipWaiting()
|
||||
})
|
||||
|
||||
self.addEventListener('activate', (e) => {
|
||||
e.waitUntil(
|
||||
caches.keys().then((keys) =>
|
||||
Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)))
|
||||
)
|
||||
)
|
||||
self.clients.claim()
|
||||
})
|
||||
|
||||
self.addEventListener('fetch', (e) => {
|
||||
// Only cache GET requests for same-origin non-API resources
|
||||
if (
|
||||
e.request.method !== 'GET' ||
|
||||
e.request.url.includes('/api/')
|
||||
) return
|
||||
|
||||
e.respondWith(
|
||||
caches.match(e.request).then((cached) => cached || fetch(e.request))
|
||||
)
|
||||
})
|
||||
Reference in New Issue
Block a user