Last active
March 12, 2018 00:23
-
-
Save ritikrishu/f303376ba3b576f651c254e23a5b2ac1 to your computer and use it in GitHub Desktop.
show fresh data from network. fallback to cache if no network available
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
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