Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save notionparallax/8a11ad093a89d097e30ec0b7b3039e3b to your computer and use it in GitHub Desktop.
Save notionparallax/8a11ad093a89d097e30ec0b7b3039e3b to your computer and use it in GitHub Desktop.
function servePhoto(request) {
var storageUrl = request.url.replace(/-\d+px\.jpg$/, '');
return caches.open(contentImgsCache).then(function(cache) {
return cache.match(storageUrl).then(function(response) {
if (response) return response;
return fetch(request).then(function(networkResponse) {
cache.put(storageUrl, networkResponse.clone());
return networkResponse;
});
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment