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
This commit is contained in:
夜坂雅 2024-10-16 18:26:03 +08:00 committed by GitHub
parent 35b0b1ea42
commit 0e51e19cab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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;