Last active
January 29, 2021 08:16
-
-
Save wanderview/f8ee22bf4b2e2bb2b2076f86f886b153 to your computer and use it in GitHub Desktop.
Example "no-op" navigation preload service worker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self.addEventListener('fetch', evt => { | |
// Fallback for subresource requests or in browsers that do not | |
// support navigation preload. | |
if (evt.request.mode !== "navigate" || !evt.preloadResponse) | |
return; | |
evt.respondWith(async _ => { | |
// Try to get the navigation preload response. | |
let r = await evt.preloadResponse; | |
// Navigation preload worked, so we are done. | |
if (r) return r; | |
// Otherwise we got an unexpected error, so switch to a pass-through | |
// fetch. | |
return fetch(evt.request); | |
}()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
s/self.addEventListener(evt => {/self.addEventListener('fetch', evt => {