Skip to content

Instantly share code, notes, and snippets.

@okjodom
Created May 11, 2018 05:23
Show Gist options
  • Select an option

  • Save okjodom/2d78664ebf1fac09cb6c5afa826d8b6e to your computer and use it in GitHub Desktop.

Select an option

Save okjodom/2d78664ebf1fac09cb6c5afa826d8b6e to your computer and use it in GitHub Desktop.
Offline first Using service workers - Broken
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