Created
May 11, 2018 05:23
-
-
Save okjodom/2d78664ebf1fac09cb6c5afa826d8b6e to your computer and use it in GitHub Desktop.
Offline first Using service workers - Broken
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', function (event) { | |
| // TODO: respond with an entry from the cache if there is one. | |
| // If there isn't, fetch from the network. | |
| const res = caches.open('wittr-static-v1').then(cache => { | |
| return cache.match(event.request).then(response => { return response; }); | |
| }); | |
| console.log(res); | |
| if (res !== undefined) { | |
| event.respondWith(res); | |
| } else { | |
| event.respondWith( | |
| fetch(event.request).then(response => { | |
| return response; | |
| }) | |
| ); | |
| } | |
| }); | |
| // spaghetti thoughts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment