ServiceWorker is a new api available in Chrome. One of the many things it lets you do is intercept network requests and respond with a cached version. I'm implementing a "take this offline" button which dynamically adds things to the cache. I'd like to report to the user how much space I'm using, and how many entries I've put in the cache.
Is it possible to query a cache to get the number of items in it? Can I report the total size of things cached in it?
cacheName.keys().then(function(keys) { keys.length })
. Currently there is no way to compute the size on disk, but you can look at thecontent-size
header for each response, but it will not exactly match whats stored on disk. (Also some http servers don't set content-size correctly.) There is open spec work around this with the quota-api and on ServiceWorkers here: github.com/slightlyoff/ServiceWorker/issues/587 – Kao