The cache
There are four types of cache: Disk, Memory, Service Worker, and push cache
Push cache is http2.0 and is currently 1.1, so I won’t discuss it. Service worker front-end configuration is also not discussed here
Caches are divided into strong caches and negotiated caches. Negotiated caches are enabled by default.
Disk cache Memory Memory caches are strong caches
Strong cache
If you set a strong cache, the first page is loaded from the disk cache. If you refresh the page, the memory cache will be loaded from the disk cache. If memory is full, anything that is not in memory is fetched from disk.
Negotiate the cache
If the page is refreshed, it compares the Etag with the backend resource to see whether the Etag is changed. If the Etag is not changed, it uses the existing resource. If the Etag is changed, it requests resources again
It is not recommended to set strong cache for HTML files. Even if you set strong cache for the first time, the browser will still use the negotiated cache if you manually refresh the cache
To set strong caching is to configure cache-control in the Response header
Personal advice cache time is set to the iterative cycle is relatively reasonable, iterative once a month if the company that is set for a month, don’t say what a third-party library basic updates can be set for a long time point, and then take a single page of the vendent, js, the third package a collection of third-party packages are not change, are you sure you won’t join the new package, or delete unused package
The overall flow of caching
Strong cache => Negotiate cache => Resource request
If either the strong cache or the negotiated cache hits, it won’t go down