当前位置:网站首页>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
边栏推荐
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- Sélectionnez toutes les lignes avec un symbole dans Word et changez - les en titre
- Is software testing outsourcing going or not? Three years' real outsourcing experience tells you
- Games101 Lesson 7 shading 1 Notes
- word设置目录
- Oracle column to row -- a field is converted to multiple rows according to the specified separator
- Supervisor usage document
- 杰理之BLE【篇】
- Lesson 12 study notes 2022.02.11
- 洛谷P1836 数页码 题解
猜你喜欢

杰理之开发板上电开机,就可以手机打开 NRF 的 APP【篇】

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower

1091: two or three things in childhood (multi instance test)

Crawling exercise: Notice of crawling Henan Agricultural University

navicat如何导入MySQL脚本

杰理之BLE【篇】
![[CF Gym101196-I] Waif Until Dark 网络最大流](/img/66/6b339fc23146b5fbdcd2a1fa0a2349.png)
[CF Gym101196-I] Waif Until Dark 网络最大流
![If Jerry's Bluetooth device wants to send data to the mobile phone, the mobile phone needs to open the notify channel first [article]](/img/d6/92ad1c6f84415de6ab0dfd16cd6073.png)
If Jerry's Bluetooth device wants to send data to the mobile phone, the mobile phone needs to open the notify channel first [article]

Fundamentals of C language 9: Functions

Go learning -- implementing generics based on reflection and empty interfaces
随机推荐
You deserve this high-value open-source third-party Netease cloud music player
Excel的相关操作
Bloom taxonomy
[dictionary tree] [trie] p3879 [tjoi2010] reading comprehension
TS 类型体操 之 循环中的键值判断,as 关键字使用
navicat如何导入MySQL脚本
leecode-C語言實現-15. 三數之和------思路待改進版
How to configure GUI guide development environment
mysql如何合并数据
Sélectionnez toutes les lignes avec un symbole dans Word et changez - les en titre
Uni app third party package configuration network request
[CF Gym101196-I] Waif Until Dark 网络最大流
TypeScript void 基础类型
The differences and advantages and disadvantages between cookies, seeion and token
OpenJudge NOI 2.1 1661:Bomb Game
位运算异或
杰理之BLE【篇】
杰理之BLE【篇】
Week6 weekly report
Set picture annotation in markdown