metasearch/sw.js

31 lines
609 B
JavaScript
Raw Normal View History

2023-10-14 12:41:06 +00:00
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)
})