performanceservice-workerworkboxcachestorage

Can bloated CacheStorage slow down Service Worker responses?


I am caching opaque responses in SW which bloats CacheStorage exponentially upto order of 6 GB+. At times, I see SW responses slower than that from the browser cache.
Can bloated CacheStorage lead to slow read and hence degraded performance while serving request through SW? How much of this performance is driven by what kind of hard drive the machine is loaded with -- SSD vs HDD?

PS: I am aware that the ideal fix is to either fix the opaque responses or not cache them at all.


Solution

  • The Cache Storage API gives you programmatic control over cache expiration, and allows you to use cached responses within JavaScript to construct complex serving/fallback strategies that work independent of the network, which is generally speaking not possible when just using the browser's HTTP cache.

    There is no specific expectation that using the Cache Storage API is going to be faster than the HTTP cache, though.

    There's some degree of overhead involved whenever service worker code is run, and the details about that overhead's impact are likely to vary based on storage medium, CPU, browser version, and any number of other criteria. I will say that I don't believe the fact that these are opaque responses comes that heavily into play when it comes to runtime performance, and the additional quota usage is effectively "fictitious". It just translates into a higher number used when calculating available quota, but does not actually result in more data being written to disk.