From 1540d883f34a888da9c2fab9feabefed6cfcb484 Mon Sep 17 00:00:00 2001 From: Percs <83934299+Percslol@users.noreply.github.com> Date: Sat, 27 Apr 2024 20:25:43 -0500 Subject: [PATCH] update example service worker --- src/sw.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/sw.js b/src/sw.js index aa71c1eb..370e7a6f 100644 --- a/src/sw.js +++ b/src/sw.js @@ -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); + })() + ); +}); \ No newline at end of file