30 lines
783 B
JavaScript
30 lines
783 B
JavaScript
const CACHE = 'status-poster-v9';
|
|
const PRECACHE = ['.', 'index.html', 'style.css', 'script.js', 'manifest.json', 'sw.js', 'icon.svg'];
|
|
|
|
self.addEventListener('install', e => {
|
|
e.waitUntil(
|
|
caches.open(CACHE)
|
|
.then(c => c.addAll(PRECACHE))
|
|
.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 => {
|
|
// Never intercept API calls — always go to network
|
|
if (e.request.url.includes('api.omg.lol')) return;
|
|
|
|
e.respondWith(
|
|
caches.match(e.request)
|
|
.then(cached => cached || fetch(e.request))
|
|
);
|
|
});
|