Skip to content

Instantly share code, notes, and snippets.

@Steph-crown
Created January 28, 2022 14:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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