HTTP缓存基础
协商缓存
If-Modified-Since/Last-modified
: 服务器程序检查请求头(request header
)里面的(If-modified-Since
),如果最后修改时间相同(例如静态文件的Modified time 通过shellls -l
可以查看)则返回304,否则给返回头(response header
)添加last-Modified
并且返回数据(response body)。If-None-Match/Etag
:服务器程序检查检查请求头(request header
)里面的if-none-match
的值与当前文件的内容通过hash算法(例如 nodejs: cryto.createHash('sha1')
)生成的内容摘要字符对比,相同则直接返回304
,否则给返回头(response header
)添加etag
属性为当前的内容摘要字符,并且返回内容。
强缓存(也就是from cache)
如果设置了
Expires
(XX时间过期)或者Cache-Control(http1.0不支持)
(经历XX时间后过期)且没有过期,命中cache
的情况下,from cache
不去发出请求。如果强刷(如ctrl+rÿ