-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsw.js
More file actions
32 lines (29 loc) · 1.27 KB
/
Copy pathsw.js
File metadata and controls
32 lines (29 loc) · 1.27 KB
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
/* LXS Wallet service worker — installs as a PWA and works offline, but ALWAYS
shows the latest version when online (network-first). RPC/faucet calls are
never cached (always hit the live network). */
const CACHE = "lxs-wallet-v3";
const ASSETS = [
"wallet.html", "wallet.js", "ethers.umd.min.js", "manifest.json",
"lxs-logo.svg", "icon-192.png", "icon-512.png", "apple-touch-icon.png"
];
self.addEventListener("install", (e) => {
e.waitUntil(caches.open(CACHE).then((c) => c.addAll(ASSETS)).catch(() => {}));
self.skipWaiting();
});
self.addEventListener("activate", (e) => {
e.waitUntil(
caches.keys().then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k))))
.then(() => self.clients.claim())
);
});
self.addEventListener("fetch", (e) => {
const url = new URL(e.request.url);
// Never intercept live network calls (balances, faucet, tx broadcast).
if (e.request.method !== "GET" || url.hostname.endsWith("duckdns.org")) return;
// App shell: NETWORK-FIRST so updates always show; fall back to cache offline.
e.respondWith(
fetch(e.request)
.then((r) => { const copy = r.clone(); caches.open(CACHE).then((c) => c.put(e.request, copy)).catch(() => {}); return r; })
.catch(() => caches.match(e.request))
);
});