Created
December 7, 2018 10:43
-
-
Save evertonstrack/4c42354022bdf6620036c2a941920dc4 to your computer and use it in GitHub Desktop.
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
// Reponde o request direto do cache | |
this.addEventListener("fetch", event => { | |
event.respondWith( | |
caches.match(event.request) | |
.then(response => { | |
// Retorna o cache | |
if (response) { | |
return response; | |
} | |
// Faz a requisição | |
return fetch(event.request); | |
}) | |
.catch(() => { | |
// Mostra uma página de offline | |
return caches.match('/offline.html'); | |
}) | |
) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment