Caching is one of the basic rules of webperf. Caching saves bandwidth and reduces loading times when the same resource is called up a second time. At least, that’s the original plan… but it turns out that’s not always the case.
In fact, not all resources that are supposed to be served by the cache actually are.
To better understand the problem, let’s take a look at the average lifetime of a resource in a cache.
You’d think that a browser would cache data once and for all, but in practice this isn’t the case. Safari, for example, implements a feature called Intelligent Tracking Protection – the cache is double-keyed based on document origin and third-party origin; Chrome also partitions its cache.
Thus, according to a Facebook study, only 42% of cached resources are more than 47 hours old, and only 25% are more than 260 hours old.
This research by Yahoo, Facebook and, more recently, Paul Calvano, indicates that resources don’t live as long in the browser cache as we might think. And when we conduct the same experiment on mobile, we find that there’s a 50% chance that our cached resource is less than 12 hours old!
In conclusion, resources don’t stay hidden for very long.
Why is cache so volatile?
Every browser has its own cache memory.- Internet Explorer: 8-50 MB
- Firefox: 50 MB
- Safari: no limit (?!)
- Chrome: less than 80 MB (depending on available disk space)
- Opera: 20 MB
What can be done about cache volatility?
To ensure that a website’s resources remain hidden, you can use LocalStorage. This allows data to be stored directly in the browser. Its storage capacity (5 MB for most browsers) is dedicated to a domain name. To date, 92.72% of browsers have deployed it:
Unlike cache, local storage has no expiration date. Once the limit has been reached, no resource is automatically deleted. It’s no longer the browser that manages storage and eviction, it’s the site itself that determines which resources are to be removed from this storage space. The volatility we’ve just described underlines the importance of optimizing your site so as to reduce the weight of resources as much as possible, and thus lighten the cache. With this in mind, he explains a number of best practices for improving first-visit loading times: image compression, minification and concatenation of JS and CSS, and the use of a CDN (global or local).Would you like to facilitate the application of these best practices and automate the optimization of your web performance?
Tagged Webperformance