| 12345678910 |
- const CACHE = 'aps-course-v4';
- const FILES = ['./','index.html','style.css','app.js','manifest.webmanifest','icons/icon.svg','icons/icon-192.png','icons/icon-512.png'];
- self.addEventListener('install', e => { e.waitUntil(caches.open(CACHE).then(c => c.addAll(FILES)).then(() => self.skipWaiting())); });
- self.addEventListener('activate', e => { e.waitUntil(caches.keys().then(ks => Promise.all(ks.filter(k => k !== CACHE).map(k => caches.delete(k)))).then(() => self.clients.claim())); });
- self.addEventListener('fetch', e => {
- if (e.request.method !== 'GET') return;
- e.respondWith(caches.match(e.request).then(r => r || fetch(e.request).then(res => {
- const copy = res.clone(); caches.open(CACHE).then(c => c.put(e.request, copy)); return res;
- }).catch(() => caches.match('index.html'))));
- });
|