Files
buuh/examples/counter/sw.js
T

29 lines
818 B
JavaScript
Raw Normal View History

/* global __BANKAI_ASSETS__ */
// Service worker built by `bankai build`: the precache list is injected
// at build time from the asset manifest (the choo-service-worker
// convention, manifest edition). Register it from your app with
// navigator.serviceWorker.register('/sw.js').
const CACHE = 'counter-v1'
const ASSETS = __BANKAI_ASSETS__
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(CACHE).then((cache) => cache.addAll(ASSETS))
)
})
self.addEventListener('activate', (event) => {
event.waitUntil(
caches.keys().then((keys) =>
Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)))
)
)
})
self.addEventListener('fetch', (event) => {
event.respondWith(
caches.match(event.request).then((hit) => hit || fetch(event.request))
)
})