We've reduced our total page size by ~98% and load time by ~35%. To accomplish this, we now cache all static, public assets for up to 1 year. Assets are also cached by our globally-distributed CDN, meaning assets will always be served from a location near you.
We content-address all of our static assets. This is a method of naming the asset based on its content, typically using a hash function. Content-addressing ensures immutability by guaranteeing that the asset's name changes whenever its content does. For example, instead of loading doppler-logo.png, we load something like doppler-logo-a24a706d.png.
This funky naming enables us to crank caching up to the max. We specify a cache policy of public, max-age=31536000, immutable, must-revalidate. Let's break down what this means:
- public allows the asset to be cached by your browser and by our CDN
- max-age=31536000 indicates the asset can be cached for 1 year
- immutable asserts that the content really doesn't need to be rechecked if unexpired (why we need this)
- must-revalidate ensures that the asset is re-requested once it expires