Last active
September 7, 2021 07:35
-
-
Save PhilJ/cd82a7616061da7b5e0c4e0444343ca6 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
// this is the service worker which intercepts all http requests | |
self.addEventListener('fetch', function fetcher (event) { | |
var request = event.request; | |
// check if request | |
if (request.url.indexOf('assets.contentful.com') > -1) { | |
// contentful asset detected | |
event.respondWith( | |
caches.match(event.request).then(function(response) { | |
// return from cache, otherwise fetch from network | |
return response || fetch(request); | |
}) | |
); | |
} | |
// otherwise: ignore event | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment