Skip to content

Instantly share code, notes, and snippets.

@flushpot1125
Created September 21, 2019 06:18
Show Gist options
  • Save flushpot1125/a58f320487de4a83eabe74a08637388b to your computer and use it in GitHub Desktop.
Save flushpot1125/a58f320487de4a83eabe74a08637388b to your computer and use it in GitHub Desktop.
const cacheName ='cache_v1';
self.addEventListener('fetch', e=> {
if (e.request.cache === 'only-if-cached' && e.request.mode !== 'same-origin'){
console.log("not same origin");
return;
}
console.log('[ServiceWorker] Fetched resources');
e.respondWith(
caches.open(cacheName)
.then(cache => cache.match(e.request, {ignoreSearch: true}))
.then(response => {
return response || fetch(e.request);
}));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment