zoukankan      html  css  js  c++  java
  • YSlow的性能测试提示

    Add an Expires or a Cache-Control Header

    tag: server

    There are two aspects to this rule:

    • For static components: implement "Never expire" policy by setting far future Expires header
    • For dynamic components: use an appropriate Cache-Control header to help the browser with conditional requests

    Web page designs are getting richer and richer, which means more scripts, stylesheets, images, and Flash in the page. A first-time visitor to your page may have to make several HTTP requests, but by using the Expires header you make those components cacheable. This avoids unnecessary HTTP requests on subsequent page views. Expires headers are most often used with images, but they should be used on all components including scripts, stylesheets, and Flash components.

    Browsers (and proxies) use a cache to reduce the number and size of HTTP requests, making web pages load faster. A web server uses the Expires header in the HTTP response to tell the client how long a component can be cached. This is a far future Expires header, telling the browser that this response won't be stale until April 15, 2010.

          Expires: Thu, 15 Apr 2010 20:00:00 GMT

    If your server is Apache, use the ExpiresDefault directive to set an expiration date relative to the current date. This example of the ExpiresDefault directive sets the Expires date 10 years out from the time of the request.

          ExpiresDefault "access plus 10 years"

    Keep in mind, if you use a far future Expires header you have to change the component's filename whenever the component changes. At Yahoo! we often make this step part of the build process: a version number is embedded in the component's filename, for example, yahoo_2.0.6.js.

    Using a far future Expires header affects page views only after a user has already visited your site. It has no effect on the number of HTTP requests when a user visits your site for the first time and the browser's cache is empty. Therefore the impact of this performance improvement depends on how often users hit your pages with a primed cache. (A "primed cache" already contains all of the components in the page.) We measured this at Yahoo! and found the number of page views with a primed cache is 75-85%. By using a far future Expires header, you increase the number of components that are cached by the browser and re-used on subsequent page views without sending a single byte over the user's Internet connection.

  • 相关阅读:
    一文带你了解接口测试价值与体系
    干货|app自动化测试之设备交互API详解
    干货|app自动化测试之Appium问题分析及定位
    干货| app自动化测试之Andriod微信小程序的自动化测试
    如果你也有这些职场困惑,周六一直线上答疑
    文末福利 | 团队管理第一步之高效招聘
    精准化测试原理简介与实践探索
    文末有福利 | 面试时如何命中面试官的考题?
    Visual studio prebuild/postbuild 设置条件不生效
    使用腾讯地图api获取定位信息经纬度(需要浏览器支持,且需要https)
  • 原文地址:https://www.cnblogs.com/wangtuda/p/3475436.html
Copyright © 2011-2022 走看看