Skip to content

Instantly share code, notes, and snippets.

@gauntface
Created January 6, 2020 04:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gauntface/7a1768d582bef8a3d6968ad296e3e105 to your computer and use it in GitHub Desktop.
Save gauntface/7a1768d582bef8a3d6968ad296e3e105 to your computer and use it in GitHub Desktop.
Trying to debug sw
function tryCache(event) {
console.log('Got request: ', event.request);
return caches.match(event.request)
.then((response) => {
if (response) {
console.log("Cache hit ", response);
return response;
}
console.log("Cache miss ", response);
return fetch(event.request);
})
.catch((error) => console.error(error));
}
self.addEventListener('fetch', (event) => {
event.respondWith(tryCache(event))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment