定义最优的 HTTP Cache-Control 缓存策略 // Code Redux 

JerryXia 发表于 , 阅读 (36)

HTTP-Cache

使用缓存和重用之前的资源的能力,则是成为前端性能优化很关键的一个方面。
每个资源都可以通过 HTTP Cache-Control 头来定义相关的缓存策略,Cache-Control 可以控制谁,以及在什么条件下重用缓存,那么如何定义最佳的 Cache-Control 策略就显得格外重要。

Cache-control

The Cache-Control general-header field is used to specify directives
that MUST be obeyed by all caching mechanisms along the
request/response chain. The directives specify behavior intended to
prevent caches from adversely interfering with the request or
response. These directives typically override the default caching
algorithms. Cache directives are unidirectional in that the presence
of a directive in a request does not imply that the same directive is
to be given in the response. —RFC2616

RFC 中定义的 Cache-Control 常用基本策略如下: