We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
所谓浏览器的缓存,就是浏览器通过 HTTP 请求网络资源后将资源留在本地的一种行为。在页面上点击 返回和前进的按钮 就是利用浏览器的缓存。
HTTP
返回和前进的按钮
强缓存
协商缓存
Service Worker, Memory Cache, Disk Cache, Push Cache
Service Worker
Push Cache
先本地再服务器
header
简单的说浏览器的缓存请求分为有无 HTTP 请求两种。
所谓的强缓存是我们没有发送 HTTP 请求,而是直接从本地缓存中获取资源的一种行为。成功后返回状态码 200。
headers
Expires/http1.0
Cache-Control/http1.1
http1.0 中一个页面的缓存字段,是一个格林时间。这个时间是浏览器强缓存资源失效的时间
Expires: Wed, 22 Nov 2021 08:41:00 GMT
上面的表示缓存的资源会在 2021年11月22号8点41分 过期。
2021年11月22号8点41分
HTTP1.1
Expires
HTTP1.1 中页面的缓存字段,如果 Expires和Cache-Control 都存在,那么Cache-Control的优先级更高。
Expires和Cache-Control
Cache-Control
max-age
Cache-Control: max-age = 3600
表示距离上次请求的一小时内可以直接使用本地的缓存。不需要再次请求。
public
private
no-cache
no-store
所谓协商缓存是指:
《图解HTTP》 浏览器缓存 前端缓存
The text was updated successfully, but these errors were encountered:
No branches or pull requests
浏览器的缓存
强缓存
和协商缓存
。Service Worker, Memory Cache, Disk Cache, Push Cache
。Service Worker
优先级最高到Push Cache
。浏览器请求资源过程
header
是否有命中强缓存,如果命中强缓存则直接请求本地的资源,不向服务器发送请求。HTTP
请求服务器,这个过程采用的就是协商缓存
强缓存
headers
字段判断Expires/http1.0
,Cache-Control/http1.1
,来执行强缓存的过程。Expires
HTTP1.1
时Expires
被放弃了。Cache-Control
Cache-Control
的属性值有很多,其中属性max-age
表示,一个相对的缓存时间public
表示可以被浏览器或代理服务器缓存。private
表示只能被浏览器缓存。no-cache
需要发送请求到服务器确认是否被缓存,这需要使用到协商缓存。no-store
表示禁止使用缓存,每一次都需要请求服务器。协商缓存
参考
《图解HTTP》
浏览器缓存
前端缓存
The text was updated successfully, but these errors were encountered: