Created
January 28, 2022 14:00
-
-
Save steph-crown/0f9041983331fe76cdb22ecdf4a07710 to your computer and use it in GitHub Desktop.
Fetch event of 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
// Runs whenever there is a fetch request | |
self.addEventListener("fetch", (event) => { | |
// Checks the cache to find matching request. | |
// If there is a cached version of the request, it returns the cached version, otherwise it makes a new request. | |
event.respondWith( | |
caches.match(event.request).then((res) => { | |
return res || fetch(event.request); | |
}) | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment