Skip to content

Instantly share code, notes, and snippets.

@ritikrishu
Last active March 12, 2018 00:23
Show Gist options
  • Save ritikrishu/f303376ba3b576f651c254e23a5b2ac1 to your computer and use it in GitHub Desktop.
Save ritikrishu/f303376ba3b576f651c254e23a5b2ac1 to your computer and use it in GitHub Desktop.
show fresh data from network. fallback to cache if no network available
self.addEventListener('fetch', event => {
event.respondWith(
fetch(event.request).catch(_ => {
return caches.match(event.request)
.then(data => {
data.isFromCache = true;
return data;
});
})
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment