. htaccess setting up a static resource cache (that is, browser caching)

Source: Internet
Author: User

Setting the expiration date or maximum presence time for static resources in the HTTP header instructs the browser to load previously downloaded resources from the local disk instead of being loaded over the network. This allows the site to load more quickly.

The following code needs to be placed in the. htaccess to take effect. The recommended setting expires at one months, which is: max-age=2592000.

Set by FilesMatch

<filesmatch ". (FLV|GIF|JPG|JPEG|PNG|ICO|SWF|CSS|JS) $ ">
Header set Cache-control "max-age=2592000"
</FilesMatch>

Set by MOD_EXPIRES.C

<ifmodule mod_expires.c>
Expiresactive on
ExpiresDefault "Access plus 1 months"
Expiresbytype text/html "Access plus 1 months"
Expiresbytype image/gif "Access plus 1 months"
Expiresbytype image/jpeg "Access plus 2 months"
Expiresbytype Application/x-shockwave-flash "Access plus 2 months"
Expiresbytype application/x-javascript "Access plus 2 months"
</IfModule>

This is required for specific resource types:

Expiresbytype image/gif "Access plus 5 hours 3 minutes"

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.