| 123456789101112131415161718192021222324252627 |
- // Offline app-shell cache. API calls are never cached.
- const CACHE = 'genrecon-v3'; // bump on shell change (app.js/viewer.js) so clients refresh
- const SHELL = [
- './', './index.html', './styles.css', './app.js', './viewer.js', './manifest.webmanifest',
- './demo.glb', './icons/icon-192.png', './icons/icon-512.png',
- './vendor/three.module.js',
- './vendor/jsm/loaders/GLTFLoader.js', './vendor/jsm/utils/BufferGeometryUtils.js',
- './vendor/jsm/math/Octree.js', './vendor/jsm/math/Capsule.js',
- ];
- self.addEventListener('install', (e) => {
- e.waitUntil(caches.open(CACHE).then((c) => c.addAll(SHELL)).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) => {
- const url = new URL(e.request.url);
- if (url.pathname.startsWith('/api/')) return; // dynamic — straight to network
- e.respondWith(caches.match(e.request).then((r) => r || fetch(e.request)));
- });
|