雅虎优化ETags

雅虎优化ETagsETags为网页资源的优化又提供了一个便捷的方案。ConfigureETagstag:serverEntitytags(ETags)areamechanismthatwebserversandbrowsersusetodeterminewhetherthecomponentinthebrowser'scachematchest

大家好,又见面了,我是你们的朋友全栈君。

ETags 为网页资源的优化又提供了一个便捷的方案。

Configure ETags

tag: 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 ETag response header.

      HTTP/1.1 200 OK
      Last-Modified: Tue, 12 Dec 2006 03:03:59 GMT
      ETag: "10c24bc-4ab-457e1c1f"
      Content-Length: 12195

 

Later, if the browser has to validate a component, it uses the If-None-Match header to pass the ETag back to the origin server. If the ETags match, a 304 status code is returned reducing the response by 12195 bytes for this example.

      GET /i/yahoo.gif HTTP/1.1
      Host: us.yimg.com
      If-Modified-Since: Tue, 12 Dec 2006 03:03:59 GMT
      If-None-Match: "10c24bc-4ab-457e1c1f"
      HTTP/1.1 304 Not Modified

 

The problem with ETags is that they typically are constructed using attributes that make them unique to a specific server hosting a site. ETags won't match when a browser gets the original component from one server and later tries to validate that component on a different server, a situation that is all too common on Web sites that use a cluster of servers to handle requests. By default, both Apache and IIS embed data in the ETag that dramatically reduces the odds of the validity test succeeding on web sites with multiple servers.

The ETag format for Apache 1.3 and 2.x is inode-size-timestamp. Although a given file may reside in the same directory across multiple servers, and have the same file size, permissions, timestamp, etc., its inode is different from one server to the next.

IIS 5.0 and 6.0 have a similar issue with ETags. The format for ETags on IIS is Filetimestamp:ChangeNumber. A ChangeNumber is a counter used to track configuration changes to IIS. It's unlikely that the ChangeNumber is the same across all IIS servers behind a web site.

The end result is ETags generated by Apache and IIS for the exact same component won't match from one server to another. If the ETags don't match, the user doesn't receive the small, fast 304 response that ETags were designed for; instead, they'll get a normal 200 response along with all the data for the component. If you host your web site on just one server, this isn't a problem. But if you have multiple servers hosting your web site, and you're using Apache or IIS with the default ETag configuration, your users are getting slower pages, your servers have a higher load, you're consuming greater bandwidth, and proxies aren't caching your content efficiently. Even if your components have a far future Expires header, a conditional GET request is still made whenever the user hits Reload or Refresh.

If you're not taking advantage of the flexible validation model that ETags provide, it's better to just remove the ETag altogether. The Last-Modified header validates based on the component's timestamp. And removing the ETag reduces the size of the HTTP headers in both the response and subsequent requests. This Microsoft Support article describes how to remove ETags. In Apache, this is done by simply adding the following line to your Apache configuration file:

      FileETag none
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/158653.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • 分布式熔断机制_服务器熔断是什么意思啊

    分布式熔断机制_服务器熔断是什么意思啊#服务熔断-“熔断器”本身是一种开关装置,当某个服务单元发生故障之后,通过断路器(hystrix)的故障监控,某个异常条件被触发,直接熔断整个服务。向调用方法返回一个符合预期的、可处理的备选响应(FallBack),而不是长时间的等待或者抛出调用方法无法处理的异常,就保证了服务调用方的线程不会被长时间占用,避免故障在分布式系统中蔓延,乃至雪崩。如果目标服务情况好转则恢复调用。服务熔断是解决服务雪崩的重要手段。#服务熔断图示…

  • 物联网数据采集

    物联网数据采集大致方案为:硬件采集数据(包含采集协议和通讯协议)硬件与网络通讯(传输数据和传输方式)网络前端的显示和展示1、硬件采集数据我们现在用到的传感器大都是有固定通讯协议的,例如串口通讯(https://blog.csdn.net/qq_36629451/article/details/76038673),模拟量与数据量的直接读取(需要硬件设备留有相应的接口)…

  • 【存储测试】vdbench存储性能测试工具

    【存储测试】vdbench存储性能测试工具 vdbench是一个I/O工作负载生成器,通常用于验证数据完整性和度量直接附加(或网络连接)存储性能。它可以运行在windows、linux环境,可用于测试文件系统或块设备基准性能。

    2022年10月26日
  • python画爱心[通俗易懂]

    python画爱心[通俗易懂]importturtleimporttime#清屏函数defclear_all():turtle.penup()turtle.goto(0,0)turtle.color(‘white’)turtle.pensize(800)turtle.pendown()turtle.setheading(0)turtle…

  • python 监控网页_python实时监控网页

    python 监控网页_python实时监控网页PHP从语言层面上讲几乎是一无是处,具体实现的质量也乏善可陈,但它胜在最要命的部署上:没有任何其他语言有像PHP一样适合大规模部署的方式。基本上装好Apache/mod_php之后,PHP应用的部署就简化为了复制文件。  即便是考虑到性能原因等采用nginx/FastCGI等替代方式,额外的工作也只是在于最初配置。一旦配置完成,之后的部署都是文件复制。服务器重启后通常会自动启动a…

  • C# 中使用正则表达式 Regex.Matches方法的几个应用[转]

    C# 中使用正则表达式 Regex.Matches方法的几个应用[转]

    2021年11月17日

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号