From 0e51e19cab5ea616c6477b368f23fa9a1796671f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9C=E5=9D=82=E9=9B=85?= <23130178+ShadowRZ@users.noreply.github.com> Date: Wed, 16 Oct 2024 18:26:03 +0800 Subject: [PATCH] fix: register service worker immediately and cache media requests (#1977) * Allow service worker to immediately claim pages * Allow media requests to be cached by browser --- src/sw.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/sw.ts b/src/sw.ts index 11f7f8b..2179dfc 100644 --- a/src/sw.ts +++ b/src/sw.ts @@ -23,9 +23,14 @@ function fetchConfig(token?: string): RequestInit | undefined { headers: { Authorization: `Bearer ${token}`, }, + cache: 'default', }; } +self.addEventListener('activate', (event: ExtendableEvent) => { + event.waitUntil(clients.claim()); +}); + self.addEventListener('fetch', (event: FetchEvent) => { const { url, method } = event.request; if (method !== 'GET') return;