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

HTTP cache in depth

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

强缓存 200

  1. Expires (HTTP/1.0) ?

  2. Cache-Control (HTTP/1.1)

max-age
s-maxage
public/ private

优先级

协商缓存 304

ETag

last-modified


浏览器缓存 / 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)中存在,一旦会话结束就被释放,并且缓存时



©xgqfrms 2012-2020

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


原文地址:https://www.cnblogs.com/xgqfrms/p/12885582.html