当前位置:网站首页>Thoroughly understand browser strong cache and negotiation cache
Thoroughly understand browser strong cache and negotiation cache
2022-07-02 15:38:00 【Mr. fingertip dancer】
At work , After the front-end code is packaged, the generated static resources will be published to the static server , At this time, we need to do some operation and maintenance configuration for these static resources , among ,gzip And setting the cache is essential . These two are the most direct impact on website performance and user experience .
The advantages of caching :
- Reduce unnecessary data transmission , Save bandwidth
- Reduce the load on the server , Improve website performance
- Speed up the client to load web pages
- User experience friendly
shortcoming :
- If the resources are changed, but the client does not update in time, it will cause users to get information lag , If the old version had bug Words , It's going to get worse .
One . Strong cache
What is strong caching ? Where is the strength ? In fact, strong means mandatory . When the browser asks for a file , The server is in respone header Cache configuration is made for the file . Cache time 、 The cache type is controlled by the server , Specific performance: :
respone header Of cache-control, Common settings are max-age public private no-cache no-store etc.
Strong cache summary
cache-control: max-age=xxxx,public
Both the client and the proxy server can cache this resource ;
The client is in xxx Within the validity period of seconds , If there is a need to request the resource, read the cache directly ,statu code:200 , If the user does a refresh operation , Send it to the server http requestcache-control: max-age=xxxx,private
Only the client can cache this resource ; The proxy server does not cache
The client is in xxx Read the cache directly within seconds ,statu code:200cache-control: max-age=xxxx,immutable
The client is in xxx Within the validity period of seconds , If there is a need to request the resource, read the cache directly ,statu code:200 , Even if the user does a refresh operation , And don't send a message to the server http requestcache-control: no-cache
Skip setting strong cache , However, it does not prevent setting the negotiation cache ; Generally, if you do strong caching , Only when the strong cache fails can the negotiation cache be used , Set up no-cache You won't strengthen the cache , Each request will ask the server back .cache-control: no-store
Don't cache , This will make the client 、 Servers don't cache , There is no so-called strong cache 、 Negotiation cache .
Two 、 Negotiate the cache
The strong cache mentioned above is to set an expiration time for resources , Every time a client requests a resource, it will see whether it has expired ; Only when it expires will you ask the server . therefore , The purpose of strong caching is to give the client self-sufficiency . And one day , When the client requests the resource, it finds that it has expired , This is to request the server , At this time, the negotiation cache can be set in the process of requesting the server . Now , Negotiation caching requires interaction between the client and the server .
reference :https://www.jianshu.com/p/9c95db596df5
边栏推荐
- Data analysis thinking analysis methods and business knowledge - business indicators
- LeetCode刷题——奇偶链表#328#Medium
- 【LeetCode】977-有序数组的平方
- 6095. 强密码检验器 II
- 11_Redis_Hyperloglog_命令
- 语义分割学习笔记(一)
- Beijing rental data analysis
- 【LeetCode】1905-统计子岛屿
- Solve the problem of frequent interruption of mobaxterm remote connection
- 【LeetCode】200-岛屿数量
猜你喜欢
LeetCode刷题——去除重复字母#316#Medium
微信支付宝账户体系和支付接口业务流程
PTA 天梯赛习题集 L2-001 城市间紧急救援
SQL transaction
Evaluation of embedded rz/g2l processor core board and development board of Feiling
[network security] network asset collection
JVM architecture, classloader, parental delegation mechanism
6.12 critical moment of Unified Process Platform
Loss function and positive and negative sample allocation: Yolo series
20_ Redis_ Sentinel mode
随机推荐
Solve the problem of frequent interruption of mobaxterm remote connection
Loss function and positive and negative sample allocation: Yolo series
Bing. Com website
搭建自己的语义分割平台deeplabV3+
folium,确诊和密接轨迹上图
I made an istio workshop. This is the first introduction
2303. 计算应缴税款总额
Data analysis thinking analysis methods and business knowledge - business indicators
08_ strand
JVM architecture, classloader, parental delegation mechanism
【LeetCode】189-轮转数组
Yolo format data set processing (XML to txt)
百变大7座,五菱佳辰产品力出众,人性化大空间,关键价格真香
Redux——详解
LeetCode刷题——验证二叉树的前序序列化#331#Medium
提前批院校名称
怎样从微信返回的json字符串中截取某个key的值?
03. Preliminary use of golang
[solution] educational codeforces round 82
【LeetCode】977-有序数组的平方