Promptly / service-worker.js
Inayatgaming's picture
Create service-worker.js
7fbc8f4 verified
raw
history blame contribute delete
548 Bytes
const CACHE_NAME = 'promptly-cache-v1';
const ASSETS = ['/', '/index.html', '/styles.css', '/app.js', '/manifest.json'];
self.addEventListener('install', (e)=>{
e.waitUntil(caches.open(CACHE_NAME).then(c=>c.addAll(ASSETS)));
self.skipWaiting();
});
self.addEventListener('activate', (e)=>{
e.waitUntil(caches.keys().then(keys=>Promise.all(keys.filter(k=>k!==CACHE_NAME).map(k=>caches.delete(k)))));
self.clients.claim();
});
self.addEventListener('fetch', (e)=>{
e.respondWith(caches.match(e.request).then(r=>r||fetch(e.request)));
});