metasearch/sw.js
2023-10-14 14:41:06 +02:00

31 lines
609 B
JavaScript

const cacheName = 'v1'
self.addEventListener('install', (event) => {
event.waitUntil(
caches
.open(cacheName)
.then(cache => cache.addAll([
'.',
'./index.html',
'./index.js',
'./index.css',
'./instances.json'
]))
)
})
self.addEventListener('activate', (_event) => {
})
self.addEventListener('fetch', async (event) => {
const res = await fetch(event.request)
if (!res.ok) {
const cachedRes = await caches.match(event.request)
if (cachedRes) {
event.respondWith(cachedRes)
return
}
}
event.respondWith(res)
})