Skip to content

Instantly share code, notes, and snippets.

@jacky810124
Created March 28, 2018 12:04
Show Gist options
  • Save jacky810124/bbf90cf1ecf3711eed70619503129b97 to your computer and use it in GitHub Desktop.
Save jacky810124/bbf90cf1ecf3711eed70619503129b97 to your computer and use it in GitHub Desktop.
PWA Day06 - on network response
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