- 网站的一些静态文件不经常更新,除了做压缩处理以优化加载,还需要做一些前端缓存;当然,接口或者全页面也可以缓存
location ~* ^.+\.(css|js|txt|xml|png|jpg|gif|jpeg|webp)$ {
add_header Cache-Control no-store;
add_header Cache-Control max-age=3600;
add_header Cache-Control public;
add_header Cache-Control only-if-cached;
add_header Cache-Control no-cache;
add_header Cache-Control must-revalidate;
}
缓存请求指令集
Cache-Control: max-age=<seconds>
Cache-Control: max-stale[=<seconds>]
Cache-Control: min-fresh=<seconds>
Cache-control: no-cache
Cache-control: no-store
Cache-control: no-transform
Cache-control: only-if-cached
缓存响应指令集 [我们使用这里的配置]
Cache-control: must-revalidate
Cache-control: no-cache
Cache-control: no-store
Cache-control: no-transform
Cache-control: public
Cache-control: private
Cache-control: proxy-revalidate
Cache-Control: max-age=<seconds>
Cache-control: s-maxage=<seconds>
可缓存性指令:
-
public: 对应POST方法,无过期。所有访问者都可以缓存
-
private: 单用户缓存,不能被代理缓存
-
no-cache: 在缓存副本前,需要和服务器校验
-
no-store: 不适用缓存
到期指令
-
max-age : 缓存最大周期,单位秒
-
s-maxage : 覆盖max-age 或 Expires 仅适用代理服务,私有服务忽略
-
max-stale : (客户端使用,慎用) 客户端愿意接受过期资源的超时时间
-
min-fresh : (客户端使用) 一定时间内保持最新状态【刷新】
其他指令/ 重加载
-
must-revalidate : 资源过期不能响应后续请求
-
proxy-revalidate : 同must-revalidate 只能用作代理,共享缓存
-
no-transform : http头不能由代理修改,不能对西苑进行转换
-
only-if-cached : 客户端只接受已缓存的响应,不向原始服务器检查是否有更新
网友评论