当前位置:网站首页>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
边栏推荐
- How to delete all the words before or after a symbol in word
- Emo diary 1
- TypeScript 变量作用域
- Related operations of Excel
- 杰理之BLE【篇】
- Leecode-c language implementation -15 Sum of three ----- ideas to be improved
- Relevant introduction of clip image
- How to configure GUI guide development environment
- JMeter performance test steps practical tutorial
- 杰理之BLE【篇】
猜你喜欢

TypeScript接口与泛型的使用

leecode-C语言实现-15. 三数之和------思路待改进版

杰理之蓝牙设备想要发送数据给手机,需要手机先打开 notify 通道【篇】

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

变量的命名规则十二条

杰理之AD 系列 MIDI 功能说明【篇】

Solution to the problem of breakthrough in OWASP juice shop shooting range

Force buckle day31

Redis builds clusters

Fundamentals of C language 9: Functions
随机推荐
TS 类型体操 之 循环中的键值判断,as 关键字使用
Win10 64 bit Mitsubishi PLC software appears oleaut32 DLL access denied
杰理之BLE【篇】
Markdown 中设置图片图注
Detailed explanation | detailed explanation of internal mechanism of industrial robot
杰理之AD 系列 MIDI 功能说明【篇】
QT color is converted to string and uint
Ble of Jerry [chapter]
Supervisor usage document
Mise en œuvre du langage leecode - C - 15. Somme des trois chiffres - - - - - idées à améliorer
杰理之普通透传测试---做数传搭配 APP 通信【篇】
Bloom taxonomy
杰理之BLE【篇】
Solution to the problem of breakthrough in OWASP juice shop shooting range
Lesson 12 study notes 2022.02.11
How can word delete English only and keep Chinese or delete Chinese and keep English
Sharing of source code anti disclosure scheme under burning scenario
JMeter performance test steps practical tutorial
Games101 Lesson 7 shading 1 Notes
How Navicat imports MySQL scripts