当前位置:网站首页>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
边栏推荐
- Excel的相关操作
- 杰理之BLE【篇】
- Project GFS data download
- C语言 简单易懂的高精度加法
- 【mysql学习笔记30】锁(非教程)
- NiO programming introduction
- Detailed explanation | detailed explanation of internal mechanism of industrial robot
- 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
- [online problem processing] how to kill the corresponding process when the MySQL table deadlock is caused by the code
- If Jerry's Bluetooth device wants to send data to the mobile phone, the mobile phone needs to open the notify channel first [article]
猜你喜欢
软件测试界的三无简历,企业拿什么来招聘你,石沉大海的简历
Leecode-c language implementation -15 Sum of three ----- ideas to be improved
杰理之BLE【篇】
NiO programming introduction
Relevant introduction of clip image
Games101 Lesson 7 shading 1 Notes
杰理之BLE【篇】
Oracle column to row -- a field is converted to multiple rows according to the specified separator
mysql如何合并数据
[MySQL learning notes 30] lock (non tutorial)
随机推荐
C - Inheritance - hidden method
OpenJudge NOI 2.1 1749:数字方格
How are the open source Netease cloud music API projects implemented?
LeetCode Algorithm 2181. Merge nodes between zero
The best way to learn SEO: search engine
Uni app third party package configuration network request
Emo diary 1
On the world of NDK (2)
qt颜色与字符串、uint相互转换
Ble of Jerry [chapter]
word中把帶有某個符號的行全部選中,更改為標題
杰理之BLE【篇】
[dictionary tree] [trie] p3879 [tjoi2010] reading comprehension
MVVM of WPF
Detailed explanation | detailed explanation of internal mechanism of industrial robot
word怎么只删除英语保留汉语或删除汉语保留英文
多线程和并发编程(二)
js对象获取属性的方法(.和[]方式)
supervisor 使用文档
可变参数重载时的内存错误