fix(pwa): make web updates deterministic (#1093)

* fix(pwa): make web updates deterministic

* fix(pwa): address review feedback
This commit is contained in:
Tommaso Casaburi
2026-03-17 16:20:13 +08:00
committed by GitHub
parent b2946e8b2e
commit f812fe1d18
11 changed files with 235 additions and 27 deletions
+14 -2
View File
@@ -3,12 +3,24 @@
import { clientsClaim } from 'workbox-core';
import { precacheAndRoute, cleanupOutdatedCaches } from 'workbox-precaching';
import { registerRoute } from 'workbox-routing';
import { NetworkFirst } from 'workbox-strategies';
declare const self: ServiceWorkerGlobalScope;
// Precache all assets specified in the manifest
const precacheEntries = self.__WB_MANIFEST.filter((entry) => (typeof entry === 'string' ? entry !== 'index.html' : entry.url !== 'index.html'));
// Precache revisioned assets, but let navigations fetch fresh HTML first.
cleanupOutdatedCaches();
precacheAndRoute(self.__WB_MANIFEST);
precacheAndRoute(precacheEntries);
registerRoute(
({ request, url }) => request.mode === 'navigate' && !url.pathname.startsWith('/api') && !/^\/_\(.*\)/.test(url.pathname),
new NetworkFirst({
cacheName: 'html-cache',
networkTimeoutSeconds: 3,
}),
);
// Standard SW lifecycle methods
self.skipWaiting();