在 Blog 盛行的今天,一些 Web 应用需要解析大量的 RSS Feed .如何提高效率是个非常重要的问题.在 MagpieRSS 的 Features 中列举了这样的一条: HTTP Conditional GETs Save bandwidth and speed up download times with intelligent use of Last-Modified and ETag.. 这里的 Etag 引起了我的注意.
什么是 Etag ?
通过阅读 RFC 2616 ,得到了对 Etag 的一点印象:
The ETag response-header field provides the current value of the entity tag for the requested variant......Entity tags are normally "strong validators," but the protocol provides a mechanism to tag an entity tag as "weak." One can think of a strong validator as one that changes whenever the bits of an entity changes, while a weak value changes whenever the meaning of an entity changes. Alternatively, one can think of a strong validator as part of an identifier for a specific entity, while a weak validator is part of an identifier for a set of semantically equivalent entities.
从上我们可以大致得知,Entity tags 本质上说是一种"强校验器",但是 HTTP 协议提供了一种通过给 Entity tags 打标签的"弱"的机制(类似于内容的校验码).虽然这段话后面通过两种方式进行了解释,但是还是有些晦涩.我看了这段话之后只是得出了 Etag 的 "E" 代表 "Entity" 而已.
Magpie 首页上提到了一篇文章: HTTP Conditional Get for RSS Hackers ,拜读之后清晰了许多.要先说说 HTTP Conditional GETs 的基本原理,很简单,就是说,从 Web 服务器取数据的时候,如果文件变化了,给我新的文件,如果文件没有变化,只需告诉客户端没有变化即可,不必再把文件取回来.这样就可节省大量的网络带宽和资源.
Etag 与 Last-Modified 是从 HTTP 1.0 到 HTTP 1.1 才有的概念.当我们从 Web 服务器获取文件的时候,只需要读取 HTTP 响应头的 Etag 与 Last-Modified 字段即可,这两个字段里面的具体内容是什么可以不管(可能会千奇百怪,RFC 2616 对 Etag 没有具体值的定义),把这两个值 Cache 在本地,下次检查文件是否更新的时候比对这两个值即可.如果没有变化,服务器的响应代码不是 HTTP 200 (OK) , 而是 304.
如上图.目前 OpenRSS 虽然订阅了40 多个 Feed,但是响应速度很不错.在使用 Gregarius 的过程中(Lilina 也应用了 ETag),发现了 FeedBurnrer 烧录的 Feed ,几乎都是用了 Etag 的(否则估计服务器要瘫痪,Hoho).我们再测试一下 HTTP header 的响应情况:
$ curl -I http://feeds.feedburner.com/dbanotes
HTTP/1.1 200 OK
Date: Tue, 25 Oct 2005 11:34:15 GMT
Server: Apache
Last-Modified: Tue, 25 Oct 2005 04:30:12 GMT
ETag: U4q478bDKLqZ8UMMC8A5afZuHug
Content-Type: text/xml;charset=utf-8
$ curl -I http://feeds.feedburner.com/dbanotes
HTTP/1.1 200 OK
Date: Tue, 25 Oct 2005 11:34:21 GMT
Server: Apache
Last-Modified: Tue, 25 Oct 2005 04:30:12 GMT
ETag: U4q478bDKLqZ8UMMC8A5afZuHug
Content-Type: text/xml;charset=utf-8
在这个期间,我的 Blog 没有更新.所以 Last-Modified 和 ETag 返回的都是相同的值.这样 Gregarius 就不必重新解析了. 国内的 GreatNews 是支持 HTTP Conditional GETs 的,更棒的是还支持 gzip/deflate encoding.而另一个 RSS 阅读工具 POPU (周博通) 就不知道了.
以上是我的笔记,如有理解错误,请指正!
分享到:
相关推荐
在 MagpieRSS 的 Features 中列举了这样的一条: HTTP Conditional GETs Save bandwidth and speed up download times with intelligent use of Last-Modified and ETag.. 这里的 Etag 引起了我的注意. 什么是 ...
GET /pic/201408/102.jpg HTTP/1.1 Host: www.jb51.net Connection: keep-alive Cache-Control: no-cache Accept: image/webp,*/*;q=0.8 Pragma: no-cache User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/...
浏览器缓存机制、Expires策略(http1.0)和Cache-control策略(http1.1)、Last-Modified/If-Modified-Since、ETag/If-None-Match
Http1.1超文本传输协议中文版,目录如下: 1 引论 7 1.1 目的 7 1.2 要求 8 1.3 术语 8 1.4 总体操作 12 2 符号习惯和一般语法 13 2.1 扩充的BNF(扩充的 ...14.25 If-Modified-Since 119 14.26 If-None-Match 120
X-Last-HTTP-Status-Code: 0 X-Retry-Count: 0 X-HTTP-Attempts: 1 Host: msedge.f.tlu.dl.delivery.mp.microsoft.com HTTP/1.1 200 OK Content-Type: application/octet-stream Content-Length: 71367168 ...
ASP.NET使用RewritePath重定向后,服务器响应的HTTP头会多个Content-Location...Last-Modified: Tue, 18 Dec 2012 15:01:50 GMT Accept-Ranges: bytes ETag: “e119ee9b30ddcd1:1c48” Server: Microsoft-IIS/6.0 X-Pow
介绍httplib2是一个全面的HTTP客户端... 消化基本的WSSE快取该模块可以选择与可理解Cache-Control:标头并使用ETag和Last-Modified缓存验证器的专用缓存一起运行。所有方法该模块可以处理任何HTTP请求方法,而不仅仅是
1、断点续传的原理(来自网络) 在了解HTTP断点续传的原理之前,先来说说HTTP协议,HTTP协议是一种基于tcp的简单协议...Last-Modified: Thu, 23 May 2002 03:05:40 GMT ETag: "bec48eb862c21:934" Content-Length: 2827
14.25 If-Modified-Since 14.26 If-None-Match 14.27 If-Range 14.28 If-Unmodified-Since 14.29 Last-Modified 14.30 Location 14.31 Max-Forwards 14.32 Pragma 14.33 Proxy-Authenticate 14.34 Proxy-...
2、静态下Apache、Lighttpd和Nginx中Etag和Expires配置3、非实时交互动态页面中Etag和Expires处理在客户端通过浏览器发出第一次请求某一个URL时,根据 HTTP 协议的规定,浏览器会向服务器传送报头(Http Request ...
页面性能指标: dns查询,一般500ms(使用dns缓存,20ms以内)协商缓存(last-modified,etag) tcp链接和ssl(https特殊的数据传输过程)大约200毫秒请求响应,内容传输dom解析(600ms左右)资源加载(http1.1同一...
11.3.3. Last-Modified/If-Modified-Since 11.3.4. ETag/If-None-Match 11.3.5. 压缩 (Compression) 11.4. 调试 HTTP web 服务 11.5. 设置 User-Agent 11.6. 处理 Last-Modified 和 ETag 11.7. 处理重定向 ...
Last-Modified: Wed, 13 Nov 2002 18:50:46 GMT Accept-Ranges: bytes Cache-Control: no-cache (“ConnectionText”) = “Dsn=ph;UID=myman;Password=mygod)” (“LDAPServer”) = “LADP://ldap.:...
10.4.2 if-modified-since 209 10.4.3 nginx proxy_pass 209 10.5 Nginx代理层缓存 212 10.5.1 Nginx代理层缓存配置 212 10.5.2 清理缓存 215 10.6 一些经验 216 参考资料 217 11 多级缓存 218 11.1 多级缓存介绍 ...
1.1. 哪一种 Python 适合您? .....................................................................................................................7 1.2. Windows 上的 Python................................