当前位置:网站首页>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
边栏推荐
- 杰理之普通透传测试---做数传搭配 APP 通信【篇】
- TypeScript 变量作用域
- 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
- Méthode d'obtention des propriétés de l'objet JS (.Et [] méthodes)
- [dictionary tree] [trie] p3879 [tjoi2010] reading comprehension
- Summary of Digital IC design written examination questions (I)
- 超级浏览器是指纹浏览器吗?怎样选择一款好的超级浏览器?
- Set picture annotation in markdown
- Word setting directory
- 数字IC设计笔试题汇总(一)
猜你喜欢

Detailed explanation | detailed explanation of internal mechanism of industrial robot
![Ble of Jerry [chapter]](/img/d8/d080ccaa4ee530ed21d62755808724.png)
Ble of Jerry [chapter]

JDBC学习笔记
![If Jerry needs to send a large package, he needs to modify the MTU on the mobile terminal [article]](/img/57/12a97ab3d2dabfaf06bbe1788450cf.png)
If Jerry needs to send a large package, he needs to modify the MTU on the mobile terminal [article]

数字IC设计笔试题汇总(一)

How to delete all the words before or after a symbol in word
![[window] when the Microsoft Store is deleted locally, how to reinstall it in three steps](/img/57/ee979a7db983ad56f0df7345dbc91f.jpg)
[window] when the Microsoft Store is deleted locally, how to reinstall it in three steps

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

Sharing of source code anti disclosure scheme under burning scenario

Related operations of Excel
随机推荐
Go learning -- implementing generics based on reflection and empty interfaces
Bit operation XOR
[MySQL learning notes 30] lock (non tutorial)
NiO programming introduction
Games101 Lesson 7 shading 1 Notes
Simulation of Teman green interferometer based on MATLAB
Summary of Digital IC design written examination questions (I)
Google可能在春节后回归中国市场。
Select all the lines with a symbol in word and change them to titles
Three treasures of leeks and Chinese men's football team
【JDBC】快速入门教程
jmeter性能测试步骤实战教程
Week6 weekly report
Leetcode 78: subset
Do you really think binary search is easy
JDBC learning notes
qt颜色与字符串、uint相互转换
【MySQL学习笔记32】mvcc
Bloom taxonomy
学go之路(一)go的基本介绍到第一个helloworld