HTTP之一 If-Modified-Since & If-None-Match

If-Modified-Since & If-None-Match
If-Modified-Since,和 Last-Modified 一样都是用于记录页面最后修改时间的 HTTP 头信息,只是 Last-Modified 是由服务器往客户端发送的 HTTP 头,而 If-Modified-Since 则是由客户端往服务器发送的头,可 以看到,再次请求本地存在的 cache 页面时,客户端会通过 If-Modified-Since 头将先前服务器端发过来的 Last-Modified 最后修改时间戳发送回去,这是为了让服务器端进行验证,通过这个时间戳判断客户端的页面是否是最新的,如果不是最新的,则返回新的内容,如果是最新的,则 返回 304 告诉客户端其本地 cache 的页面是最新的,于是客户端就可以直接从本地加载页面了,这样在网络上传输的数据就会大大减少,同时也减轻了服务器的负担。
If-None-Match,它和ETags(HTTP协议规格说明定义ETag为“被请求变量的实体值”,或者是一个可以与Web资源关联的记号)常用来判断当前请求资源是否改变。类似于Last-Modified和HTTP-IF-MODIFIED-SINCE。但是有所不同的是Last-Modified和HTTP-IF-MODIFIED-SINCE只判断资源的最后修改时间,而ETags和If-None-Match可以是资源任何的任何属性,不如资源的MD5等。
ETags和If-None-Match的工作原理是在HTTP Response中添加ETags信息。当客户端再次请求该资源时,将在HTTP Request中加入If-None-Match信息(ETags的值)。如果服务器验证资源的ETags没有改变(该资源没有改变),将返回一个304状态;否则,服务器将返回200状态,并返回该资源和新的ETags。
  
ETag如何帮助提升性能? 
聪明的服务器开发者会把ETags和GET请求的“If-None-Match”头一起使用,这样可利用客户端(例如浏览器)的缓存。因为服务器首先产生ETag,服务器可在稍后使用它来判断页面是否已经被修改。本质上,客户端通过将该记号传回服务器要求服务器验证其(客户端)缓存。
其过程如下:
  1.客户端请求一个页面(A)。 
  2.服务器返回页面A,并在给A加上一个ETag。 
  3.客户端展现该页面,并将页面连同ETag一起缓存。 
  4.客户再次请求页面A,并将上次请求时服务器返回的ETag一起传递给服务器。

5.服务器检查该ETag,并判断出该页面自上次客户端请求之后还未被修改,直接返回响应304(未修改——Not Modified)和一个空的响应体。

时间: 2024-07-29 22:43:54

HTTP之一 If-Modified-Since & If-None-Match的相关文章

Android ContentProvider、ContentResolver和ContentObserver的使用

1.ContentProvider.ContentResolver和ContentObserver ContentProvider是Android的四大组件之一,可见它在Android中的作用非同小可.它主要的作用是:实现各个应用程序之间的(跨应用)数据共享,比如联系人应用中就使用了ContentProvider,你在自己的应用中可以读取和修改联系人的数据,不过需要获得相应的权限.其实它也只是一个中间人,真正的数据源是文件或者SQLite等. 一个应用实现ContentProvider来提供内容

Oracle Global Finanicals Technical Reference(二)

Skip Headers Oracle Global Finanicals Oracle Global Financials Technical Reference Manual Release 11i       European Region (EMEA) Flexfields European flexfields are included in the setup and transaction windows of Oracle General Ledger, Payables, an

Redis Clients Handling

This document provides information about how Redis handles clients from the point of view of the network layer: connections, timeouts, buffers, and other similar topics are covered here. The information contained in this document is only applicable t

Oracle Global Finanicals Oracle Global Financials Technical Reference(一)

Skip Headers Oracle Global Finanicals Oracle Global Financials Technical Reference Manual Release 11i         Globalization Flexfields This document describes the globalization flexfields that store certain pieces of country- and region-specific info

Logstash+Elasticsearch+Kibana+Nginx set up our private log query system

Logstash+Elasticsearch+Kibana+S3+Nginx build our private log query system System structure How to setup Logstash-index (Logstash server) yum -y install java-1.7.0-openjdk Install and configure Elasticsearch ( Logstash 1.4.2 recommends Elasticsearch 1

UVA 10100Longest Match

Longest Match A newly opened detective agency is struggling with their limited intelligence to find out a secret information passing technique among its detectives. Since they are new in this profession, they know well that their messages will easily

The parent virtual disk has been modified since the child was created

Problem: 具体的消息是: Failed to start the virtual machine. Module DiskEarly power on failed. Cannot open the disk '/vmfs/volumes/54627907-c2477c60-ec2b-0024e8573a7f/WebServer_Version2/WebServer_Version 2-000008.vmdk' or one of the snapshot disks it depend

深度剖析Reges.Match

在翻阅前辈写的代码的时候,看到前辈写的一个正则表达式,经过几番调试,都没有搞懂Regex.March.现查阅资料,好好的学习一下基础! 这是我要匹配的和值和规则 你能判断 1.var cdata="^$=No"; 2.var cdata=".+=Yes"; 根据两个不同的cdata,你能看出输出的结果吗,如果能,那可以不需要往下看了,说明你已经掌握了 var sv="伟"; string ptnConfigData = "^(?<

Make jQuery throw error when it doesn&#39;t match an element

Make jQuery throw error when it doesn't match an element 解答1 You could make a plugin to use to ensure that the jQuery object is not empty: $.fn.ensure = function() { if (this.length === 0) throw "Empty jQuery result." return this; } Usage: $('ul

maven -- 问题解决(三)Java compiler level does not match the version of the installed Java project facet

问题: Java compiler level does not match the version of the installed Java project facet 解决方法如下: properties->Java Compiler,修改JDK版本,然后Apply