Bypass event.respondWith for some paths (#12953)

This commit is contained in:
Fernando Valverde 2021-03-09 16:06:26 -06:00 committed by GitHub
parent 0460f96347
commit e6a2df73bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -35,10 +35,20 @@
self.clients.claim();
});
function includesUnsupportedPath(url) {
return [
'/%F0%9F%92%B8', // 💸 (hiring)
'/admin', // Don't run on admin dashboard.
'/oauth/', // Skip oauth apps
'/onboarding', // Don't run on onboarding.
'/users/auth', // Don't run on authentication.
].some(path => url.includes(path))
}
self.addEventListener("fetch", (event) => {
// We only want to call event.respondWith() if this is a navigation request
// for an HTML page.
if (event.request.mode === "navigate") {
// for an HTML page with a few exceptions.
if (event.request.mode === "navigate" && !includesUnsupportedPath(event.request.url)) {
event.respondWith(
(async () => {
try {
@ -72,4 +82,4 @@
// event.respondWith(), the request will be handled by the browser as if there
// were no service worker involvement.
});
<% end %>
<% end %>