remove our stupid ass service worker
Some checks failed
Nicolium CI / Test and upload artifacts (22.x) (push) Has been cancelled
Nicolium CI / release (push) Has been cancelled
Nicolium CI / deploy (push) Has been cancelled
pl-api CI / Test for pl-api formatting (22.x) (push) Has been cancelled
pl-hooks CI / Test for a successful build (22.x) (push) Has been cancelled

This commit is contained in:
2026-03-23 02:01:10 +00:00
parent a4a05c5133
commit 227ec780ff

View File

@ -326,56 +326,12 @@ const handleNotificationClick = (event: NotificationEvent) => {
event.waitUntil(reactToNotificationClick);
};
// --- Asset caching ---
const CACHE_NAME = 'ncd-assets-v3';
/** URL patterns to cache with a cache-first strategy. */
const CACHEABLE_PATTERNS = [
/\/packs\/assets\/.*\.woff2?$/, // Font files
/\/emoji\/.*\.(png|svg|gif|webp)$/, // Custom instance emojis
];
const isCacheable = (url: string): boolean =>
CACHEABLE_PATTERNS.some((pattern) => pattern.test(url));
/** Cache-first fetch handler for static assets. Falls back to network on any error. */
const handleFetch = (event: FetchEvent) => {
const { request } = event;
if (request.method !== 'GET' || !isCacheable(request.url)) return;
event.respondWith(
caches
.match(request)
.then((cached) => {
if (cached) return cached;
return fetch(request).then((response) => {
if (response.ok && response.status === 200) {
const clone = response.clone();
caches.open(CACHE_NAME).then((cache) => cache.put(request, clone));
}
return response;
});
})
.catch(() => fetch(request)),
);
};
/** Clean up old caches on activation. */
/** Clean up any leftover caches from previous versions. */
const handleActivate = (event: ExtendableEvent) => {
event.waitUntil(
caches
.keys()
.then((keys) =>
Promise.all(keys.filter((key) => key !== CACHE_NAME).map((key) => caches.delete(key))),
),
);
event.waitUntil(caches.keys().then((keys) => Promise.all(keys.map((key) => caches.delete(key)))));
};
// ServiceWorker event listeners
self.addEventListener('push', handlePush);
self.addEventListener('notificationclick', handleNotificationClick);
self.addEventListener('fetch', handleFetch);
self.addEventListener('activate', handleActivate);