Skip to content

Instantly share code, notes, and snippets.

@ritikrishu
Last active March 12, 2018 00:13
Show Gist options
  • Save ritikrishu/c0ab94889bc5603365e13e964e43a188 to your computer and use it in GitHub Desktop.
Save ritikrishu/c0ab94889bc5603365e13e964e43a188 to your computer and use it in GitHub Desktop.
respond with static files from cache only.
//no network call is made, only local store is looked into
self.addEventListener('fetch', function (event) {
const requestUrl = new URL(event.request.url);
if(myItemsToPrefetchRequestArray.contains(requestUrl){
event.respondWith(
caches.open(staticCacheName).then(
cache => cache.match(event.request)
)
)
return;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment