Created
November 18, 2015 15:05
-
-
Save roman01la/c7144b36a8a2c907586e to your computer and use it in GitHub Desktop.
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', async (event) => { | |
const response = await fetch(event.request); | |
const cache = await caches.open('cache-v1'); | |
if (response.ok === true) { | |
cache.put(event.request, response); | |
event.respondWith(response); | |
} else { | |
event.respondWith(cache.match(event.request)); | |
} | |
}); |
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( | |
fetch(event.request).then((response) => { | |
return caches.open('cache-v1').then((cache) => { | |
if (response.ok === true) { | |
cache.put(event.request, response); | |
return response; | |
} else { | |
return cache.match(event.request); | |
} | |
}); | |
})); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment