Skip to content

Commit

Permalink
Only handle sameOrigin routes
Browse files Browse the repository at this point in the history
  • Loading branch information
russss committed May 23, 2024
1 parent 60f3d85 commit 5a27574
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions web/src/sw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ declare let self: ServiceWorkerGlobalScope
function register(match_url: string, strategy: any) {
const prefix = '/'

registerRoute(({ url }) => url.pathname.startsWith(prefix + match_url), strategy)
registerRoute(
({ url, sameOrigin }) => sameOrigin && url.pathname.startsWith(prefix + match_url),
strategy
)
}

precacheAndRoute(self.__WB_MANIFEST)
Expand All @@ -21,7 +24,10 @@ register('maps', new NetworkFirst())

try {
// Only catch requests to the root URL (a regex doesn't do this).
registerRoute(({ url }) => url.pathname == '/', createHandlerBoundToURL('index.html'))
registerRoute(
({ url, sameOrigin }) => sameOrigin && url.pathname == '/',
createHandlerBoundToURL('index.html')
)
} catch (e) {
// This fails in dev as index.html is not in the manifest.
}
Expand Down

0 comments on commit 5a27574

Please sign in to comment.