Created
September 21, 2019 06:18
-
-
Save flushpot1125/a58f320487de4a83eabe74a08637388b to your computer and use it in GitHub Desktop.
This file contains 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
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