Created
October 2, 2017 07:47
-
-
Save osvaldasvalutis/01a7a441f29b533c4aca771e1017e95b to your computer and use it in GitHub Desktop.
Service Worker gotchas – https://medium.com/kollegorna/service-worker-gotchas-af20a9dab986
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
const appLangs = ['en', 'sv'], | |
url = new URL(event.request.url); | |
event.respondWith( | |
fetch(event.request).then(response => { | |
// ... | |
return response; | |
}) | |
.catch(function() { | |
let lang = url.pathname.substr(1, 2); | |
lang = appLangs.includes(lang) ? lang : appLangs[0]; | |
return caches.match(`/${lang}/offline/`); | |
}) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment