@rmdes/indiekit-frontend 1.0.0-beta.34 → 1.0.0-beta.35
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/lib/serviceworker.js +7 -3
- package/package.json +1 -1
package/lib/serviceworker.js
CHANGED
|
@@ -91,9 +91,10 @@ async function clearPagesCache() {
|
|
|
91
91
|
* Notify all clients that the service worker has been updated
|
|
92
92
|
*/
|
|
93
93
|
async function notifyClients() {
|
|
94
|
+
const version = assetCacheName.replace("assets-", "");
|
|
94
95
|
const allClients = await clients.matchAll({ includeUncontrolled: true });
|
|
95
96
|
for (const client of allClients) {
|
|
96
|
-
client.postMessage({ command: "SW_UPDATED", version
|
|
97
|
+
client.postMessage({ command: "SW_UPDATED", version });
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
100
|
|
|
@@ -130,7 +131,10 @@ self.addEventListener("activate", async (event) => {
|
|
|
130
131
|
event.waitUntil(
|
|
131
132
|
(async () => {
|
|
132
133
|
await clearOldCaches();
|
|
133
|
-
|
|
134
|
+
// Don't clear pages cache on activate — stale cached pages provide a
|
|
135
|
+
// valuable fallback when the network is slow (e.g. right after a deploy).
|
|
136
|
+
// The network-first fetch strategy naturally updates cached pages on
|
|
137
|
+
// every successful navigation, so stale entries are short-lived.
|
|
134
138
|
await clients.claim();
|
|
135
139
|
await notifyClients();
|
|
136
140
|
})(),
|
|
@@ -161,7 +165,7 @@ self.addEventListener("fetch", (event) => {
|
|
|
161
165
|
// For HTML requests, try network with timeout, fall back to cache
|
|
162
166
|
if (
|
|
163
167
|
request.mode === "navigate" ||
|
|
164
|
-
request.headers.get("Accept").includes("text/html")
|
|
168
|
+
(request.headers.get("Accept") || "").includes("text/html")
|
|
165
169
|
) {
|
|
166
170
|
event.respondWith(
|
|
167
171
|
(async () => {
|