Skip to content

Commit

Permalink
fix: register service worker immediately and cache media requests (#1977
Browse files Browse the repository at this point in the history
)

* Allow service worker to immediately claim pages
* Allow media requests to be cached by browser
  • Loading branch information
ShadowRZ authored Oct 16, 2024
1 parent 35b0b1e commit 0e51e19
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/sw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0e51e19

Please sign in to comment.