sw.js 1.1 KB

123456789101112131415161718192021222324252627
  1. // Offline app-shell cache. API calls are never cached.
  2. const CACHE = 'genrecon-v3'; // bump on shell change (app.js/viewer.js) so clients refresh
  3. const SHELL = [
  4. './', './index.html', './styles.css', './app.js', './viewer.js', './manifest.webmanifest',
  5. './demo.glb', './icons/icon-192.png', './icons/icon-512.png',
  6. './vendor/three.module.js',
  7. './vendor/jsm/loaders/GLTFLoader.js', './vendor/jsm/utils/BufferGeometryUtils.js',
  8. './vendor/jsm/math/Octree.js', './vendor/jsm/math/Capsule.js',
  9. ];
  10. self.addEventListener('install', (e) => {
  11. e.waitUntil(caches.open(CACHE).then((c) => c.addAll(SHELL)).then(() => self.skipWaiting()));
  12. });
  13. self.addEventListener('activate', (e) => {
  14. e.waitUntil(
  15. caches.keys()
  16. .then((ks) => Promise.all(ks.filter((k) => k !== CACHE).map((k) => caches.delete(k))))
  17. .then(() => self.clients.claim()),
  18. );
  19. });
  20. self.addEventListener('fetch', (e) => {
  21. const url = new URL(e.request.url);
  22. if (url.pathname.startsWith('/api/')) return; // dynamic — straight to network
  23. e.respondWith(caches.match(e.request).then((r) => r || fetch(e.request)));
  24. });