Skip to content

Instantly share code, notes, and snippets.

@Steph-crown
Created Jan 28, 2022
Embed
What would you like to do?
Fetch event of service worker
// 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