const CACHE_NAME = 'offline-v1'; const ASSETS = [ '/css/main.css', '/js/shared/theme.js', '/js/post/download.js', '/js/post/lazyimg.js', '/package/js/prism.min.js', '/package/js/prism-python.min.js', '/package/js/mathjax.js', '/css/icons/back.webp', '/css/icons/written.webp', '/css/icons/date.webp', '/css/icons/magnifier.webp', '/css/icons/save.webp', '/css/icons/script.webp' ]; self.addEventListener('install', e => { e.waitUntil(caches.open(CACHE_NAME).then(c => c.addAll(ASSETS))); }); self.addEventListener('fetch', e => { e.respondWith( caches.match(e.request).then(res => res || fetch(e.request).then(resp => { if (e.request.url.startsWith(self.location.origin)) { const copy = resp.clone(); caches.open(CACHE_NAME).then(c => c.put(e.request, copy)); } return resp; })) ); });