-
-
Save svenyurgensson/3c14936afafc153cb2e6 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