Created
October 11, 2019 19:12
-
-
Save jeffposnick/9bc877a477031872ec8fb9851f81a526 to your computer and use it in GitHub Desktop.
Snippet to get the total size of everything in the Cache Storage API for the current origin
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
async function totalCacheSize() { | |
let size = 0; | |
const cacheNames = await caches.keys(); | |
for (const cacheName of cacheNames) { | |
const cache = await caches.open(cacheName); | |
const cachedRequests = await cache.keys(); | |
for (const cachedRequest of cachedRequests) { | |
const cachedResponse = await cache.match(cachedRequest); | |
const responseBlob = await cachedResponse.blob(); | |
size += responseBlob.size; | |
} | |
} | |
return totalContentSize; | |
} | |
// Can the be used in the JS console: | |
// totalContentSize().then(console.log); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment