Created
March 22, 2018 15:38
-
-
Save jacky810124/6a8784c7546c80f96b2db7e2845bb285 to your computer and use it in GitHub Desktop.
PWA Day05 - fetch event
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 => { | |
console.log('[Service Worker] - fetch event') | |
event.respondWith( | |
self | |
.caches | |
.match(event.request) | |
.then(result => { | |
if (result == null) { | |
return fetch(event.request) | |
} | |
return result | |
}) | |
.catch(error => { | |
console.error('Fetch Failed', error) | |
}) | |
) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment