Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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