html
location / {
# 其它配置
...
if ($request_uri ~* .*[.](js|css|map|jpg|png|svg|ico)$) {
#非html缓存1个月
add_header Cache-Control "public, max-age=2592000";
}
if ($request_filename ~* ^.*[.](html|htm)$) {
#html文件使用协商缓存
add_header Cache-Control "no-cache";
}
}
作者:苏苏同学
链接:https://juejin.cn/post/7052527032491573279express测试中发现
假如你是浏览器回车拿的图片
req cache-control是自动带上max-age=0的,他一直会走协商缓存304 res cache-control默认是public, max-age=0 就算后台res手动改Cache-Control: max-age=10,他还是走304
假如是img标签获取资源
request里是没cache-control的 response里就默认有Cache-Control: public, max-age=0, 后面会走一小会304,然后再200,大概10秒吧 后台设置的话 res.header('Cache-Control', 'no-cache');// 走协商缓存 304 res.header('Cache-Control', 'max-age=10');// 走强缓存 200
xxxsjan Docs