xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

HTTP cache in depth All In One

HTTP cache in depth All In One

HTTP 缓存

https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching?hl=zh-CN

https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Caching_FAQ

HTTP Headers 不区分大小写 ✅

HTTP headers are not case sensitive ???

https://stackoverflow.com/questions/5258977/are-http-headers-case-sensitive

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/

强缓存 200

  1. Expires (HTTP/1.0) 👎

  2. Cache-Control (HTTP/1.1) 👍

max-age
s-maxage
public
private

优先级 Cache-Control

协商缓存 304

HTTP 304 Not Modified 说明无需再次传输请求的内容,也就是说可以使用缓存的内容。这通常是在一些安全的方法(safe),例如GET 或HEAD 或在请求中附带了头部信息: If-None-Match 或If-Modified-Since。

如果是 200 OK ,响应会带有头部 Cache-Control, Content-Location, Date, ETag, Expires,和 Vary.

https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Status/304

https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Status/200

ETag / If-None-Match
Last-Modified / If-Modified-Since

优先级 ETag

强缓存 & 协商缓存

强缓存:
expires
Cache-Control

协商缓存:
ETag / If-None-Match
Last-Modified / If-Modified-Since

image

浏览器缓存 / web 缓存

  1. Memory Cache
  2. Service Worker
  3. HTTP cache
  4. Application Cache API (已弃用⚠️)

...

memory cache

200

cache-control / ETag

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9

https://github.com/h5bp/server-configs

http://httparchive.org/trends.php#maxage0

PWA

cookie

LocalStorage

SessionStorage

IndexedDB

Web SQL (已弃用⚠️,停止维护,支持者太少了,sqlite)

https://developers.google.com/web/tools/chrome-devtools/storage/applicationcache

https://html.spec.whatwg.org/multipage/offline.html#offline

https://developers.google.com/web/tools/chrome-devtools/storage/websql

https://www.w3.org/TR/webdatabase/#status-of-this-document

https://www.sqlite.org/

HTTP/1.1 HTTP/2 HTTP/3 (QUIC)

  1. 多路复用

http cache 缓存的位置

https://segmentfault.com/a/1190000020086923

从缓存位置上来看,分为4种,从上往下依次检查是否命中,如果但都没有命中则重新发起请求。

Service Worker 是运行在浏览器背后的独立线程,一般可以用来实现缓存功能。
使用 Service Worker的话,传输协议必须为 HTTPS。

Memory Cache 也就是内存中的缓存,主要包含的是当前中页面中已经抓取到的资源,例如页面上已经下载的样式、脚本、图片等。读取内存中的数据肯定比磁盘快,内存缓存虽然读取高效,可是缓存持续性很短,会随着进程的释放而释放。
一旦我们关闭 Tab 页面,内存中的缓存也就被释放了。
内存缓存中有一块重要的缓存资源是preloader相关指令(例如)下载的资源。
它可以一边解析js/css文件,一边网络请求下一个资源。

Disk Cache 也就是存储在硬盘中的缓存,读取速度慢点,但是什么都能存储到磁盘中,比之 Memory Cache 胜在容量和存储时效性上。
绝大部分的缓存都来自Disk Cache,在HTTP 的协议头中设置。

Push Cache(推送缓存)是 HTTP/2 中的内容,当以上三种缓存都没有命中时,它才会被使用。
它只在会话(Session)中存在,一旦会话结束就被释放,并且缓存时

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

refs



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2020-05-13 23:06  xgqfrms  阅读(218)  评论(8编辑  收藏  举报