Skip to content

Commit

Permalink
update example service worker
Browse files Browse the repository at this point in the history
  • Loading branch information
Percslol committed Apr 28, 2024
1 parent 743c99f commit 1540d88
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ importScripts('uv.bundle.js');
importScripts('uv.config.js');
importScripts(__uv$config.sw || 'uv.sw.js');

const sw = new UVServiceWorker();
const uv = new UVServiceWorker();

self.addEventListener('fetch', (event) => event.respondWith(sw.fetch(event)));
self.addEventListener('fetch', event => {
event.respondWith(
(async ()=>{
if(event.request.url.startsWith(location.origin + __uv$config.prefix)) {
return await uv.fetch(event);
}
return await fetch(event.request);
})()
);
});

0 comments on commit 1540d88

Please sign in to comment.