@boluo-ai/relay 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/web-dist/service-worker.js +53 -19
package/package.json
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
|
-
// App-shell service worker.
|
|
2
|
-
//
|
|
1
|
+
// App-shell service worker.
|
|
2
|
+
//
|
|
3
|
+
// Strategy split (this matters — old versions used cache-first for everything
|
|
4
|
+
// which permanently pinned users to whatever HTML they first saw and made
|
|
5
|
+
// redeployments invisible):
|
|
6
|
+
//
|
|
7
|
+
// /assets/* → cache-first (Vite emits fingerprinted filenames, so a
|
|
8
|
+
// new build produces a new URL; cached entries
|
|
9
|
+
// for old URLs become harmless garbage that
|
|
10
|
+
// activate() purges on next SW upgrade).
|
|
11
|
+
// /ws, /api/* → bypassed entirely (live data must never be cached).
|
|
12
|
+
// everything → network-first with cache fallback. New deploys take effect
|
|
13
|
+
// else on the next page load, not whenever the user manually
|
|
14
|
+
// unregisters the SW.
|
|
15
|
+
//
|
|
16
|
+
// On `SW_VERSION` change, activate() deletes every other cache key so users
|
|
17
|
+
// pick up the new shell deterministically. Bump it when you change this
|
|
18
|
+
// strategy.
|
|
3
19
|
|
|
4
|
-
const SW_VERSION = 'boluo-
|
|
5
|
-
const APP_SHELL = ['/
|
|
20
|
+
const SW_VERSION = 'boluo-v2';
|
|
21
|
+
const APP_SHELL = ['/index.html', '/manifest.json'];
|
|
6
22
|
|
|
7
23
|
self.addEventListener('install', (e) => {
|
|
8
24
|
e.waitUntil(caches.open(SW_VERSION).then((c) => c.addAll(APP_SHELL)));
|
|
@@ -18,22 +34,40 @@ self.addEventListener('activate', (e) => {
|
|
|
18
34
|
self.clients.claim();
|
|
19
35
|
});
|
|
20
36
|
|
|
37
|
+
function cacheFirst(request) {
|
|
38
|
+
return caches.match(request).then((hit) =>
|
|
39
|
+
hit ||
|
|
40
|
+
fetch(request).then((net) => {
|
|
41
|
+
if (net.ok) {
|
|
42
|
+
const clone = net.clone();
|
|
43
|
+
caches.open(SW_VERSION).then((cache) => cache.put(request, clone));
|
|
44
|
+
}
|
|
45
|
+
return net;
|
|
46
|
+
}),
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function networkFirst(request) {
|
|
51
|
+
return fetch(request)
|
|
52
|
+
.then((net) => {
|
|
53
|
+
if (net.ok) {
|
|
54
|
+
const clone = net.clone();
|
|
55
|
+
caches.open(SW_VERSION).then((cache) => cache.put(request, clone));
|
|
56
|
+
}
|
|
57
|
+
return net;
|
|
58
|
+
})
|
|
59
|
+
.catch(() =>
|
|
60
|
+
caches.match(request).then((hit) => hit || caches.match('/index.html')),
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
21
64
|
self.addEventListener('fetch', (e) => {
|
|
22
|
-
const u = new URL(e.request.url);
|
|
23
65
|
if (e.request.method !== 'GET') return;
|
|
66
|
+
const u = new URL(e.request.url);
|
|
24
67
|
if (u.pathname === '/ws' || u.pathname.startsWith('/api')) return;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (net.ok) {
|
|
31
|
-
const c = net.clone();
|
|
32
|
-
caches.open(SW_VERSION).then((cache) => cache.put(e.request, c));
|
|
33
|
-
}
|
|
34
|
-
return net;
|
|
35
|
-
})
|
|
36
|
-
.catch(() => caches.match('/index.html')),
|
|
37
|
-
),
|
|
38
|
-
);
|
|
68
|
+
if (u.pathname.startsWith('/assets/')) {
|
|
69
|
+
e.respondWith(cacheFirst(e.request));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
e.respondWith(networkFirst(e.request));
|
|
39
73
|
});
|