相关概念

http 相关缓存字段

Expires 缓存过期时间
Cache-Control 缓存配置信息
image.png
Last-Modified 资源最后修改时间
ETag 资源标签值

浏览器请求流程

image.png

强缓存 浏览器直接使用本地缓存
弱缓存 服务器对缓存进行判断,返回304,浏览器再使用本地缓存

http_headers

expires

| Syntax: | expires [modified] time;
expires epoch | max | off;

| | —- | —- | | Default: | expires off; | | Context: | http, server, location, if in location

|

time
正数或0 Cache-Control:max-age=time # 单位秒
s m h d w M y 指定 秒 分 时 天 周 月 年

负数 Cache-Control:no-cache # 缓存过不过期都会向服务端发起缓存求证

epoch
将 Expires 设置为 “Thu, 01 Jan 1970 00:00:01 GMT” , Cache-Control 设置为 no-cache
max
将 Expires 设置为 “Thu, 31 Dec 2037 23:55:55 GMT” , Cache-Control 设置为 10年
off 不缓存

add_header

| Syntax: | add_header name value [always];

| | —- | —- | | Default: | — | | Context: | http, server, location, if in location

|

添加相应头 k:v