Commit fcd72af 1 parent d6751d6 commit fcd72af Copy full SHA for fcd72af
File tree 2 files changed +404
-0
lines changed
2 files changed +404
-0
lines changed Original file line number Diff line number Diff line change
1
+ #关于缓存 (大纲)
2
+
3
+ > 存储很便宜 但是流量太贵
4
+
5
+ Cache 缓存? 快取?
6
+
7
+ ## 从 200 和 304 说起
8
+
9
+ 通过 charles 或 Findller 模拟各种情景
10
+
11
+ ` Cache-Control: max-age `
12
+
13
+ ### 强缓存
14
+
15
+ ### 协商缓存 需要验证
16
+
17
+ 静态资源或者接口内容可能会变化
18
+
19
+ 1 . 验证机制
20
+ 2 . 验证过程
21
+
22
+ ### 关于 Cache-Control
23
+
24
+ HTTP 1.1 的标准
25
+
26
+ [ MDN上的详细说明] ( https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Cache-Control )
27
+
28
+ 1 . no-cache
29
+ 2 . no-store
30
+
31
+ ### 关于 Expires
32
+
33
+ HTTP 1.0 的标准
34
+
35
+ 会出现时区问题
36
+
37
+ ### Etag 和 Last-Modified
38
+
39
+ Etag 强验证
40
+ Last-Modified 弱验证
41
+
42
+ [ 规范要求] ( http://www.ietf.org/rfc/rfc2616.txt )
43
+
44
+ 13.3.4 Rules for When to Use Entity Tags and Last-Modified Dates
45
+
46
+ ### public private
47
+
48
+
49
+ ## 设计缓存的决策树
50
+
51
+ ![ ] ( https://img.alicdn.com/tfs/TB1xKqrSVXXXXbyXpXXXXXXXXXX-595-600.png )
52
+
53
+
54
+ ## serviceWorker 缓存
55
+
56
+ [ Google 对sw缓存使用] ( https://developers.google.com/web/fundamentals/getting-started/primers/service-workers )
57
+
58
+
59
+
60
+ PS: 网络请求 -> sw.js -> HTTP缓存
61
+
62
+
63
+ sw.js 中的请求向服务端去验证
64
+
65
+ ``` js
66
+ self .addEventListener (' install' , event => {
67
+ event .waitUntil (
68
+ caches .open (CACHE_NAME )
69
+ .then (cache => cache .addAll ([
70
+ new Request (' /styles/main.css' , { cache: ' no-cache' }),
71
+ new Request (' /styles/main.js' , { cache: ' no-cache' })
72
+ ]))
73
+ );
74
+ });
75
+
76
+ ```
77
+
78
+ ### 缓存顺序
79
+
80
+ 200 from Cache (memory disc) -> sw -> HTTP Cache -> HTTP2 push
81
+
82
+ [ HTTP2 PUSH] ( https://jakearchibald.com/2017/h2-push-tougher-than-i-thought/ )
83
+
84
+
85
+
86
+ ## 其他的缓存
87
+
88
+ 1 . localStorage sessionStorage
89
+ 2 . [ HTTP2] ( https://github.com/ccforward/cc/issues/36 )
90
+ 3 . 新版本提前下发资源
91
+
92
+ ### 常用缓存淘汰算法
93
+
94
+ 1 . FIFO
95
+ 2 . LFU
96
+ 3 . LRU Vue.js 1.x 浏览器
97
+
98
+
99
+
100
+
101
+
102
+
You can’t perform that action at this time.
0 commit comments