Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save okjodom/cf2a6721466a328fc8b473c59b28b3b3 to your computer and use it in GitHub Desktop.
Offline first Using service workers, after coffee break, Yaay!
(coffee break).then( freshMind => {
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.
event.respondWith(
caches.open('wittr-static-v1').then(cache => {
return cache.match(event.request).then(response => {
if (!response) {
return fetch(event.request);
}
return response;
});
})
);
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment