当前位置:网站首页>http缓存,强制缓存,协商缓存
http缓存,强制缓存,协商缓存
2022-07-06 07:25:00 【让代码飞1926】
什么是缓存?
浏览器加载网页的时候,需要加载一些资源,html,css,js,img...,第一次需要全部请求,当第二次,第三次访问这个网页的时候,其实可以不要重复发送请求,就可以使用到http缓存策略,使得网页加载速度变快。
强制缓存
浏览器向服务端发送请求,服务器要返回给客户端资源,但是客户端想把这些资源缓存起来,就需要设置响应头cache-control:max-age=31536000,这样浏览器就会把资源缓存起来,下次请求的时候就检查max-age有没有过期,如果没过期,就直接拿资源,如果过期了,就发请求,如果不使用缓存就使用no-cache
协商缓存
使用协商缓存的话,浏览器第一次发起请求,服务器会返回资源和资源标识,然后把资源放在本地,在下一次请求的时候,发送请求和资源标识一起给服务器,服务器来判断发过来的标识和服务器上的最新资源标识,如果是最新的,服务器就返回304状态码,直接从缓存里面拿资源,如果不是最新的,就返回200状态码和最新的资源和资源标识
资源标识:
有两种,一种是last-Modified:资源上一次修改时间,只能精确到秒,发送请求的时候带的键名是:if-Modified-Since
一种是ETag:资源对应的唯一字符串,发送请求的时候带的键名是:if-None-Match,优先使用ETag
边栏推荐
- Oracle column to row -- a field is converted to multiple rows according to the specified separator
- ORACLE列转行--某字段按指定分隔符转多行
- Yield method of tread
- Twelve rules for naming variables
- word中把带有某个符号的行全部选中,更改为标题
- 1091: two or three things in childhood (multi instance test)
- You deserve this high-value open-source third-party Netease cloud music player
- Ble of Jerry [chapter]
- TS 类型体操 之 循环中的键值判断,as 关键字使用
- 烧录场景下的源代码防泄密方案分享
猜你喜欢
Oracle database 11gr2 uses TDE transparent data encryption to report an error ora28353. If you run to close the wallet, you will report an error ora28365. If you run to open the wallet, you will repor
杰理之蓝牙设备想要发送数据给手机,需要手机先打开 notify 通道【篇】
Relevant introduction of clip image
Path analysis model
Typescript interface and the use of generics
JDBC学习笔记
1091: two or three things in childhood (multi instance test)
杰理之如若需要大包发送,需要手机端修改 MTU【篇】
Simulation of holographic interferogram and phase reconstruction of Fourier transform based on MATLAB
Games101 Lesson 7 shading 1 Notes
随机推荐
Typescript void base type
Typescript interface properties
Methods for JS object to obtain attributes (. And [] methods)
Simulation of holographic interferogram and phase reconstruction of Fourier transform based on MATLAB
Leecode-c language implementation -15 Sum of three ----- ideas to be improved
word中把带有某个符号的行全部选中,更改为标题
可变参数重载时的内存错误
洛谷P1836 数页码 题解
合规、高效,加快药企数字化转型,全新打造药企文档资源中心
TypeScript 接口属性
#systemverilog# 可綜合模型的結構總結
[MySQL learning notes 32] mvcc
Related operations of Excel
TS 体操 &(交叉运算) 和 接口的继承的区别
Structure summary of SystemVerilog integrable model
Three no resumes in the software testing industry. What does the enterprise use to recruit you? Shichendahai's resume
js對象獲取屬性的方法(.和[]方式)
【mysql学习笔记30】锁(非教程)
Typescript variable scope
TS 类型体操 之 extends,Equal,Alike 使用场景和实现对比