2025-05-22 17:42:04 +02:00
|
|
|
/// <reference lib="webworker" />
|
|
|
|
|
/* eslint-disable no-restricted-globals */
|
|
|
|
|
|
|
|
|
|
import { clientsClaim } from 'workbox-core';
|
|
|
|
|
import { precacheAndRoute, cleanupOutdatedCaches } from 'workbox-precaching';
|
2026-03-17 16:20:13 +08:00
|
|
|
import { registerRoute } from 'workbox-routing';
|
|
|
|
|
import { NetworkFirst } from 'workbox-strategies';
|
2025-05-22 17:42:04 +02:00
|
|
|
|
|
|
|
|
declare const self: ServiceWorkerGlobalScope;
|
|
|
|
|
|
2026-03-17 16:20:13 +08:00
|
|
|
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.
|
2025-05-22 17:42:04 +02:00
|
|
|
cleanupOutdatedCaches();
|
2026-03-17 16:20:13 +08:00
|
|
|
precacheAndRoute(precacheEntries);
|
|
|
|
|
|
|
|
|
|
registerRoute(
|
|
|
|
|
({ request, url }) => request.mode === 'navigate' && !url.pathname.startsWith('/api') && !/^\/_\(.*\)/.test(url.pathname),
|
|
|
|
|
new NetworkFirst({
|
|
|
|
|
cacheName: 'html-cache',
|
|
|
|
|
networkTimeoutSeconds: 3,
|
|
|
|
|
}),
|
|
|
|
|
);
|
2025-05-22 17:42:04 +02:00
|
|
|
|
|
|
|
|
// Standard SW lifecycle methods
|
|
|
|
|
self.skipWaiting();
|
|
|
|
|
clientsClaim();
|