/* Sigsprig offline cache. (c) 2026 CyberMax. All rights reserved. */ /* 16 Oct 2026: './' is not precached: the Hugging Face static host answers 404 for a folder URL, which made the whole install fail (no offline). Navigations fall back to index.html. */ var CACHE = 'sigsprig-v2'; var CORE = ['index.html', 'style.css', 'pro.js', 'lib/sig.js', 'app.js', 'manifest.webmanifest', 'icon.svg', 'icon-192.png', 'icon-512.png', 'sample/photo.png']; ['dark', 'grey', 'square'].forEach(function (s) { ['linkedin', 'instagram', 'facebook', 'x', 'tiktok', 'youtube', 'whatsapp', 'pinterest', 'telegram', 'threads', 'github', 'calendar'].forEach(function (n) { CORE.push('icons/' + s + '/' + n + '.png'); }); }); ['cdark', 'cgrey'].forEach(function (s) { ['phone', 'mail', 'web', 'pin'].forEach(function (n) { CORE.push('icons/' + s + '/' + n + '.png'); }); }); self.addEventListener('install', function (e) { e.waitUntil(caches.open(CACHE).then(function (c) { return c.addAll(CORE); }).then(function () { return self.skipWaiting(); })); }); self.addEventListener('activate', function (e) { e.waitUntil(caches.keys().then(function (keys) { return Promise.all(keys.filter(function (k) { return k.indexOf('sigsprig-') === 0 && k !== CACHE; }).map(function (k) { return caches.delete(k); })); }).then(function () { return self.clients.claim(); })); }); self.addEventListener('fetch', function (e) { var req = e.request; if (req.method !== 'GET') return; var u = new URL(req.url); if (u.origin !== location.origin) return; if (req.mode === 'navigate') { // network first so updates arrive quickly; cached page when offline e.respondWith(fetch(req).then(function (r) { var copy = r.clone(); caches.open(CACHE).then(function (c) { c.put('index.html', copy); }); return r; }).catch(function () { return caches.match('index.html'); })); return; } var scope = self.registration.scope; if (req.url.indexOf(scope) !== 0) return; // cache first for static files in this app's folder e.respondWith(caches.match(req, { ignoreSearch: true }).then(function (hit) { return hit || fetch(req).then(function (r) { if (r.ok) { var copy = r.clone(); caches.open(CACHE).then(function (c) { c.put(req, copy); }); } return r; }); })); });