Web front-end performance Optimization (iii) Add Expires headers

Source: Internet
Author: User

This article turns from: http://www.chinaz.com/web/2015/0417/399716.shtml



what is expires head.

Expires stores a date that is used to control the expiration of a cache. When the browser sees a expires header in the response, it is saved with the corresponding component in its cache, and as long as the component does not expire, the browser uses the cached version without any HTTP requests. The date format for the expires setting must be GMT (Greenwich Standard Time).



Another option for caching in the HTTP1.1 protocol

There are obvious deficiencies in expires.

First, the Expires header uses a specific time, requiring the client and server-side clocks to be strictly synchronized. What is strict synchronization. We know that the client's time can be modified, if the server and the client time is not uniform, which leads to a possible cache premature failure of the situation, there is instability. Second, if the expires date arrives, a new date will need to be provided in the server configuration.

In the face of this situation, HTTP1.1 introduced a cache-control head to overcome the limitations of the expires head. Cache-control uses Max-age to define how long a component is cached, using seconds, such as cache-control:max-age=3600, to indicate that the component will be cached for 60 minutes. If Max-age and expires are present at the same time, the max-age has a higher priority, and the browser confirms the cache expiration time based on the max-age time.

Cache-control In addition to setting up Max-age, you can set additional labels at the same time. Common labels as shown in the following illustration:



How to configure an expired cache.

Under ASP.net, you can configure caching by Web.config files.

<span style= "FONT-SIZE:18PX;" ><span style= "FONT-FAMILY:SIMSUN;FONT-SIZE:14PX;" ><!--individually configured expires-->
<system.webServer>
    <staticContent>
        <clientcache Cachecontrolmode= "Useexpires" httpexpires= "Sun, Mar 2020 00:00:00 GMT"/><!--indicates that the expiration date is March 29, 2020-->
    </staticContent>
</system.webServer>
<!--individually configured max-age-->
<system.webServer>
    <staticContent>
        <clientcache cachecontrolmode= "usemaxage" cachecontrolmaxage= "30.00:01:00" ><!--indicates that the expiration time is (30*24*60*60+60) s after-->
    </staticContent>
</system.webServer>
</span></span>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.