Created
March 28, 2018 12:04
-
-
Save jacky810124/bbf90cf1ecf3711eed70619503129b97 to your computer and use it in GitHub Desktop.
PWA Day06 - on network response
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', function(event) { | |
event.respondWith( | |
self | |
.caches | |
.open('mysite-dynamic') | |
.then(function(cache) { | |
return cache | |
.match(event.request) | |
.then(function (response) { | |
if (response != null) { | |
return response | |
} | |
return fetch(event.request) | |
.then(function(response) { | |
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