雅虎优化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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 【转载】.NET Remoting学习笔记(二)激活方式

    【转载】.NET Remoting学习笔记(二)激活方式

    2021年11月18日
    88
  • 海思Hi3798处理器参数,Hi3798芯片详细信息介绍

    海思Hi3798处理器参数,Hi3798芯片详细信息介绍Hi3798CV200集成4核64位高性能CortexA53处理器、内置NEON加速引擎,强大的CPU处理能力可以满足各种差异化的业务需求。在码流兼容性、在线视频播放的流畅性、图像质量以及整机性能方面保持业界最好的用户体验。支持4K2KP60@10bit超高清视频解码和显示,支持H.265/HEVC、H.264/AVC、AVS+、MVC、MPEG2、MPEG4、VC-1、VP6、VP…

    2022年6月30日
    114
  • Teleport Ultra/Pro 1.72 安装+便携版(备份网站内容工具+离线网页浏览)[通俗易懂]

    Teleport Ultra/Pro 1.72 安装+便携版(备份网站内容工具+离线网页浏览)[通俗易懂]TeleportPro由美国TennysonMaxwell公司开发,曾被PCMagazine评为”编辑选择奖”、ZDNet评为五星。它可以完全或部分下载一个网站上的内容,使用户能够离线浏览;可以在硬盘上创建一个与原网站完全相同的镜象;可以在网站上寻找并下载某一类型的文件;可以探测并记录一个网站的所有网页和文件的清单;可以从一个中心网站探测每一个与之链接的网站。TeleportPro支持HTML4.0、CSS2.0、DHTML和Javaapplet,实现了能够处理所有类型网站上的文件;它可以同..

    2022年9月8日
    0
  • 百度网站链接怎么分享_url的组成部分有哪些

    百度网站链接怎么分享_url的组成部分有哪些百度分享默认分享的是当前页的url,但也可以在同一个页面中分享多个不同的url,仅需进行如下简单的配置。默认的代码如下:其实是有很多隐藏的参数的:’bdDes’:’您的自定义分享摘要’, //’请参考自定义分享摘要”text’:’您的自定义分享内容’, //’请参考自定义分享内容”title’:’您的自定义pop窗口标题’, //’请参考自定义p

    2022年10月8日
    0
  • linux修改密码长度限制_linux文件名长度限制修改

    linux修改密码长度限制_linux文件名长度限制修改修改密码长度:设置为不少于8位的。修改最短密码长度需要编辑login.defs文件(vi/etc/login.defs),把下面这行PASS_MIN_LEN5(默认的情况)改为PASS_MIN_LEN8(修改后的情况)login.defs文件是login程序的配置文件 转载于:https://blog.51ct…

    2022年9月5日
    3
  • 目录爆破工具_dir是什么意思中文

    目录爆破工具_dir是什么意思中文在github中下下来网址:https://github.com/maurosoria/dirsearch下载下来我是用的kail所以我把它也放在kail里面了dirsearch需要python3,kail中是自带的进入dirsearch目录后执行./dirsearch.py-u10.0.3.45-ephp-u指定url-…

    2022年10月5日
    0

发表回复

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

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