File size: 2,008 Bytes
7947900
5112876
 
 
7947900
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* Platesprig 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 = "platesprig-v2";
var FILES = ["index.html", "style.css", "pro.js", "lib/cost.js", "app.js", "manifest.webmanifest", "icon.svg", "icon-192.png", "icon-512.png"];
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("platesprig-") === 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;
  }));
});