Last active
August 10, 2016 20:56
-
-
Save jeffposnick/34bc77369c0e53a9d975cfdd76338ed8 to your computer and use it in GitHub Desktop.
Total size, in bytes, of all entries in the Cache Storage API
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
// Note that any opaque (i.e. cross-domain, without CORS) responses in the cache will return a size of 0. | |
caches.keys().then(cacheNames => { | |
let total = 0; | |
return Promise.all( | |
cacheNames.map(cacheName => { | |
// Change this to match the cache name filter you want. | |
if (!cacheName.includes('sw-precache')) { | |
return; | |
} | |
return caches.open(cacheName).then(cache => { | |
return cache.keys().then(keys => { | |
return Promise.all( | |
keys.map(key => { | |
return cache.match(key) | |
.then(response => response.arrayBuffer()) | |
.then(buffer => total += buffer.byteLength); | |
}) | |
); | |
}); | |
}); | |
}) | |
).then(() => console.log(`Total bytes: ${total}`)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment