Skip to content

Commit

Permalink
Avoid intercepting in SW when not app URL
Browse files Browse the repository at this point in the history
When not intercepting an app URL, and not adding COI headers, we can
avoid a copy in the service worker by not intercepting the request at
all.
  • Loading branch information
georgestagg committed Jul 14, 2024
1 parent 2baf804 commit 273c5cb
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/shinylive-sw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,14 @@ self.addEventListener("fetch", function (event): void {
return;
}

event.respondWith(
(async (): Promise<Response> => {
const resp = await fetch(request);
if (coiRequested) {
if (coiRequested) {
event.respondWith(
(async (): Promise<Response> => {
const resp = await fetch(request);
return addCoiHeaders(resp);
} else {
return resp;
}
})(),
);
})(),
);
}
});

// =============================================================================
Expand Down

0 comments on commit 273c5cb

Please sign in to comment.