mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(pwa): make web updates deterministic (#1093)
* fix(pwa): make web updates deterministic * fix(pwa): address review feedback
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user