I have been analyzing the cache storage use of complex application, when I realized that the stored image or script with certain content-length N
actually takes 5N-10N
space in the cache storage.
Consider this sample: I am requesting image from OpenStreetMap via service worker and storing it in cache. There is only one image stored in cache. The Chrome version is the latest one (Version 65.0.3325.146 (Official Build) (64-bit)).
This is the view of cache storage after refresh:
This is the view of clear cache tab:
So, the problem is that the image which has the size of 6.4KB
actually takes 13.8MB
of cache storage. Am I missing something?
The live example can be seen at https://googlechrome.github.io/samples/service-worker/basic/ - less than 10KB
of scripts occupy almost 50KB
of cache storage.
So, the question is: how comes that when files are cached via service workers the space that they occupy significantly increases? I agree that the actual request weights more that actual response, but not 10 times more.
Links that might be useful:
In the Chrome appTap History Clear browsing data. At the top, choose a time range. To delete everything, select All time. Next to “Cookies and site data” and “Cached images and files,” check the boxes.
Chrome runs each tab as a separate new process. This is to make sure that you get a fast browsing experience along with high stability. So when you have multiple open tabs running in your browser, more processes need to be executed. This results in Chrome taking up a lot of memory.
They make your online experience easier by saving browsing data. The cache remembers parts of pages, like images, to help them open faster during your next visit.
In the case of OSM tiles, the high cache usage comes from opaque requests.
When you cache something from another domain, you are only allowed to cache it and not see the contents in any way. This makes the request opaque. You cannot fiddle with the contents in your code, only cache it, it's a black box. To avoid information leakage browsers implement padding when they cache the resource. For this reason an image of 100kb is reported to take 7mb of your cache, and the actual reported size differs from browser to browser.
This only means you will be able to cache a lot less opaque requests in the SW logic before a quota exceeded exception will be thrown. All of the cached requests – even if very small actually – take lots of (padded) space in the cache to avoid information leakage.
In the second case I think it's a bug.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With