CyberMax-tools's picture
Deploy pactsprig to the hub
1f46816 verified
Raw History Blame Contribute Delete
2.14 kB
/* Pactsprig offline cache. © 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 = "pactsprig-v2";
var FILES = ["index.html", "style.css", "pro.js", "lib/core.js", "lib/pdf.js", "lib/docx.js", "app.js", "manifest.webmanifest", "icon.svg", "icon-192.png", "icon-512.png",
"templates/index.json", "templates/mnda.json", "templates/psa.json", "templates/design-partner.json"];
self.addEventListener("install", function (e) {
e.waitUntil(caches.open(CACHE).then(function (c) { return c.addAll(FILES); }).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("pactsprig-") === 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, url = new URL(req.url);
if (req.method !== "GET" || url.origin !== location.origin) return;
var scope = new URL(self.registration.scope);
if (url.pathname.indexOf(scope.pathname) !== 0) return;
if (req.mode === "navigate") {
// Network first for pages so updates arrive quickly; the cached page works 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;
}
// Cache first for static files in this app's folder, refreshed in the background.
e.respondWith(caches.match(req, { ignoreSearch: true }).then(function (hit) {
var net = fetch(req).then(function (r) {
if (r && r.ok) { var copy = r.clone(); caches.open(CACHE).then(function (c) { c.put(req, copy); }); }
return r;
});
if (hit) { net.catch(function () { /* offline */ }); return hit; }
return net;
}));
});