前言
关于缓存的定义,可以去看我另一篇文章的介绍:浏览器/web-缓存知识点梳理
1·expires和Cache-Control
1.1·expires
使用本指令可以控制HTTP应答中的“Expires”和“Cache-Control”的头标,(起到控制页面缓存的作用)。
语法: expires [time|epoch|max|off
默认值: expires off
作用域: http, server, location
例如
配置成负数,就会变成”Cache-Control: no-cache“
配置成整数。就会变成“Cache-Control:max-age=#”,# 为指定时间的秒数。
配置成1d的话,浏览器中就可以看到“Cache-Control:max-age=86400”,86400就是1天的秒数
location /img {
alias /export/img/;
expires 1d;
}
1.2·Cache-Control
nginx也可以通过添加返回头,来修改Cache-Control的值:
cache-control :
max-age>0时 直接从游览器缓存中提取;
max-age<=0 时向server发送http请求确认 ,该资源是否有修改, 有的