Created
May 5, 2016 21:11
-
-
Save jeffposnick/bd71531ee19537c568474e1f834e34fb to your computer and use it in GitHub Desktop.
Given a list of URLs, check to see whether each of them are already stored in a cache
This file contains hidden or 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 CACHE_NAME = 'my-cache'; // Or whatever your cache is. | |
let urls = []; // An array of full, absolute URLs that may or may not be cached. | |
caches.open(CACHE_NAME) | |
.then(cache => cache.keys()) | |
.then(responses => responses.map(response => response.url)) | |
.then(urlsInCache => Promise.all(urls.map(url => { | |
return { | |
url: url, | |
cached: urlsInCache.includes(url) | |
}; | |
}))).then(urlCacheStatuses => { | |
// Do something with each item in the urlCacheStatuses array, | |
// i.e. change the display of the UI element corresponding to | |
// item.url if item.cached is true. | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment