Last-Modified,Etag,Expire区别
Last-Modified 是什么
Last-Modified 是 HttpHeader 中的资源的最后修改时间,如果带有 Last-Modified ,下一次发送 Http 请求时,将会发生带 If-modified-since 的 HttpHeader 。如果没有过期,将会收到 304 的响应,从缓存中读取。
Etag 是什么
Etag 是 HttpHeader 中代表资源的标签,在服务器端生成。如果带有 Etag ,下一次发送带 Etag 的请求,如果 Etag 没有变化将收到 304 的响应,从缓存中读取。
Etag 在使用时要注意相同资源多台 Web 服务器的 Etag 的一致性。
Expire 是什么
Expire 是 HttpHeader 中代表资源的过期时间,由服务器段设置。如果带有 Expire ,则在 Expire 过期前不会发生 Http 请求,直接从缓存中读取。用户强制 F5 例外。
Last-Modified,Etag,Expire 混合
通常 Last-Modified,Etag,Expire 是一起混合使用的,特别是 Last-Modified 和 Expire 经常一起使用,因为 Expire 可以让浏览器完全不发起 Http 请求,而当浏览器强制 F5 的时候又有 Last-Modified ,这样就很好的达到了浏览器段缓存的效果。
Etag 和 Expire 一起使用时,先判断 Expire ,如果已经过期,再发起 Http 请求,如果 Etag 也过期,则返回 200 响应。如果 Etag 没有过期则返回 304 响应。
Last-Modified,Etag,Expires 三个同时使用时。先判断 Expire ,然后发送 Http 请求,服务器先判断 last-modified ,再判断 Etag ,必须都没有过期,才能返回 304 响应。
第一次访问 200
鼠标点击二次访问 (Cache)
按F5刷新 304
按Ctrl+F5强制刷新 200
为什么要去掉ETag?
使用YSlow对网页进行优化的时候,给的一个建议是Configure Entity Tags(ETag)。这个纠结了好久,最后终于搞明白了。Yahoo网站上面的解释是这样的:
Configure ETagstag: server Entity tags (ETags) are a mechanism that web servers and browsers use to determine whether the component in the browser's cache matches the one on the origin server. (An "entity" is another word a "component": images, scripts, stylesheets, etc.) ETags were added to provide a mechanism for validating entities that is more flexible than the last-modified date. An ETag is a string that uniquely identifies a specific version of a component. The only format constraints are that the string be quoted. The origin server specifies the component's ETag using the HTTP/1.1 200 OK Later, if the browser has to validate a component, it uses the GET /i/yahoo.gif HTTP/1.1 The problem with ETags is that they typically are constructed using The ETag format for Apache 1.3 and 2.x is IIS 5.0 and 6.0 have a similar issue with ETags. The format for ETags on IIS is The end result is ETags generated by Apache and IIS for the exact If you're not taking advantage of the flexible validation model FileETag none |
大概思想就是在集群服务器上面,因为ETag的值会很服务器有关,那么对于同样的文件,可能下次请求的时候是发给不同的服务器,结果也会重新发送数据,所以就会影响网页加载速度,增加服务器的压力。一般情况下就要把Etag给去掉,只是用Last_modified和Expire。
如何去掉ETag?
在Apache里面去掉很简单,但是IIS里面去掉就有点棘手,网上有IIS各个的解决方法。我的版本是IIS 8, 使用URL Rewrite解决了,解决方案如下:
|
If you prefer to not send the ETag HTTP header for files served from IIS 7 or 7.5, it is a bit problematic. To the best of my knowledge, IIS does not provide a straight forward way to remove this header. This post shows a way to do it using Microsoft's URL Rewrite Module 2.0. I'm not going to go into the what and why of the ETag. Suffice it to say, many web developers and web masters would prefer not to send it. The ETag can be removed using an outbound URL rewrite rule. You can read more about it at the URL Rewrite Module 2.0 Configuration Reference. The rewrite rule that can be put in your web.config follows:
This graphic shows the settings for the ETag removal rewrite rule in IIS Manager. In fact, if you look at the headers for the image, you'll see there is no ETag :-)
If you happen to be using Helicon's Ape, then this is very simple as well. You can use a mod_headers rule like:
I hope this helps :-) |
什么时候使用ETag?
Last-Modified,Etag,Expire区别的更多相关文章
- [转]【技术心得】Last-Modified,Etag,Expire区别
Last-Modified 是什么 Last-Modified 是 HttpHeader 中的资源的最后修改时间,如果带有 Last-Modified ,下一次发送 Http 请求时,将会发生带 If ...
- Entity Framework 更新模式之Attach与EntityState.Modified模式的区别
数据库中有一个City表 初始时数据: 实体类与Fluent Api配置映射 public class City { public int Id { get; set; } public string ...
- 基于Yahoo网站性能优化的34条军规及自己的见解
1.尽量减少HTTP请求次数 终端用户响应的时间中,有80%用于下载各项内容,这部分时间包括下载页面中的图像.样式表.脚本.Flash等.通过减少页面中的元素可以减少HTTP请求的次数,这是提高网页速 ...
- 【转】优化Web程序的最佳实践
自动排版有点乱,看着蛋疼,建议下载中文PDF版阅读或阅读英文原文. Yahoo!的Exceptional Performance团队为改善Web性能带来最佳实践.他们为此进行了 一系列的实验.开发了各 ...
- Yahoo!网站性能最佳体验的34条黄金守则(转载)
1. 尽量减少HTTP请求次数 终端用户响应的时间中,有80%用于下载各项内容.这部分时间包括下载页面中的图像.样式表.脚本.Flash等.通过减少页面中的元素可以减少HTTP请求的次数 ...
- yslow性能优化的35条黄金守则
参考Best Practices for Speeding Up Your Web Site Exceptional Performance 团队总结了一系列优化网站性能的方法,分成了7个大类35条, ...
- 网站性能优化(Yahoo 35条)
Yahoo 网站性能优化 35条 一.内容部分 尽量减少 HTTP请求 减少 DNS查找 避免跳转 缓存 Ajxa 推迟加载 提前加载 减少 DOM元素数量 用域名划分页面内容 使 frame数量最少 ...
- 【转】Yahoo!团队:网站性能优化的35条黄金守则
Yahoo!的 Exceptional Performance团队为改善 Web性能带来最佳实践.他们为此进行了一系列的实验.开发了各种工具.写了大量的文章和博客并在各种会议上参与探讨.最佳实践的核心 ...
- Yahoo团队经验:网站性能优化的34条黄金法则
Yahoo团队总结的关于网站性能优化的经验,非常有参考价值.英文原文:http://developer.yahoo.com/performance/rules.html 1.尽量减少HTTP请求次数 ...
随机推荐
- vs.net git版本仓库使用 之解决冲突方法 原创
vs.net git 之解决冲突方法 如果别人已经修改推送到服务器,但自已本地未进行同部更新,那么就会出现要解决冲突的提示! 具体解决方法为: ... ... 下载word离线版:vs.net_git ...
- MySQL分表自增ID解决方案
当我们对MySQL进行分表操作后,将不能依赖MySQL的自动增量来产生唯一ID了,因为数据已经分散到多个表中. 应尽量避免使用自增IP来做为主键,为数据库分表操作带来极大的不便. 在postgreSQ ...
- 可输出sql的PrepareStatement封装
import java.io.InputStream; import java.io.Reader; import java.net.URL; import java.sql.Connection; ...
- Mysql 创建用户 授权
一, 创建用户: 命令:CREATE USER 'username'@'host' IDENTIFIED BY 'password'; 说明:username - 你将创建的用户名, host - 指 ...
- 烂泥:【解决】NFS服务器使用showmount –e命令报错
本文由秀依林枫提供友情赞助,首发于烂泥行天下. 今天在NFS服务器使用showmount –e查看NFS共享目录时,发现系统一直显示如下错误: clnt_create: RPC: Port mappe ...
- scp报错:not a regular file,解决方法:加参数 -r
命令:scp -P1234 /data/aa root@192.0.0..0:/data 文件结构:/data/aa/yearmonth=2015-09 报错:not a regular fi ...
- 记录遇到的Python陷阱和注意点
最近使用Python的过程中遇到了一些坑,例如用datetime.datetime.now()这个可变对象作为函数的默认参数,模块循环依赖等等. 在此记录一下,方便以后查询和补充. 避免可变对象作为默 ...
- 《Remus: High Availability via Asychronous Virtual Machine Replication》翻译
Abstract 想要让应用能够躲过硬件故障是一项非常昂贵的任务,因为这通常意味着对软件进行重构,使它包含复杂的恢复逻辑的同时需要部署专用的硬件,而这些对于提升大型的或者遗留的应用的可靠性是巨大的障碍 ...
- NYOJ-756重建二叉树
重建二叉树 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 题目很简单,给你一棵二叉树的后序和中序序列,求出它的前序序列(So easy!). 输入 输入有多组数据(少于 ...
- NOIP2003传染病控制[按层DFS]
题目背景 近来,一种新的传染病肆虐全球.蓬莱国也发现了零星感染者,为防止该病在蓬莱国大范围流行,该国政府决定不惜一切代价控制传染病的蔓延.不幸的是,由于人们尚未完全认识这种传染病,难以准确判别病毒携带 ...
