雅虎优化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
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

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

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • linux使用ps命令查看和控制进程_使用ps命令得到当前进程

    linux使用ps命令查看和控制进程_使用ps命令得到当前进程ps命令Linuxps(英文全拼:processstatus)命令用于显示当前进程的状态,类似于windows的任务管理器查看所有进程ps-A显示所有进程信息,连同命令行ps-

    2022年7月30日
    10
  • potplayer快捷键

    potplayer快捷键potplayer播放器用起来感觉不错,搜集快捷键备用快捷键指令——————————————————–“播放->跳略播放->跳略播放开|关’播放->跳略播放->跳略播放设置…,字幕->字幕同步(帧率)->滞后0.5秒Alt+,…

    2022年5月11日
    101
  • Tensor和NumPy相互转换「建议收藏」

    Tensor和NumPy相互转换我们很容易用numpy()和from_numpy()将Tensor和NumPy中的数组相互转换。但是需要注意的一点是:这两个函数所产生的Tensor和NumPy中的数组共享相同的内存(所以他们之间的转换很快),改变其中一个时另一个也会改变!1.Tensor转NumPya=torch.ones(6)b=a.numpy()print(a,b)a+=1print(a,b)b+=1print(a,b)tensor([1.,1.

    2022年4月5日
    371
  • 什么软件可以激活成功教程网址_bya意思

    什么软件可以激活成功教程网址_bya意思国内激活成功教程站点大全![http://blog.csdn.net/netxiaoyue/archive/2005/01/29/273559.aspx]国内激活成功教程站点大全!(强烈推荐)【8DD资源中心】-http://www.18dd.com/精品软件秀-http://www.ohsoft.com/163软件园-http://www.soft163.com/中华激活成功教程联盟

    2025年12月7日
    6
  • 双机热备系统的方案与软件浅析「建议收藏」

    一、概述双机热备指基于高可用系统中的两台服务器的热备(或高可用),因两机高可用在国内使用较多,故得名双机热备。双机高可用按工作中的切换方式分为:主-备方式(Active-Standby方式)和双主机方式(Active-Active方式),主-备方式指的是一台服务器处于某种业务的激活状态(即Active状态),另一台服务器处于该业务的备用状态(即Standby状态)。而双主机方式即指两种不同业务分别在

    2022年4月6日
    49
  • 数据库优化 – SQL优化[通俗易懂]

    数据库优化 – SQL优化[通俗易懂]以实际SQL入手,带你一步一步走上SQL优化之路!

    2025年10月7日
    4

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

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