Created
October 11, 2017 09:51
-
-
Save aofleejay/ae79e6db3eaca8bff8b3ff8e8391a5b6 to your computer and use it in GitHub Desktop.
Handle network request to use cache storage
This file contains hidden or 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( | |
caches.match(event.request).then(cacheResp => { | |
return cacheResp || fetch(event.request).then(response => { | |
return caches.open(CACHE_KEY).then(cache => { | |
cache.put(event.request, response.clone()) | |
return response | |
}) | |
}) | |
}) | |
) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment