Apache Configure static cache

Source: Internet
Author: User

Apache Configure static cache

Here static file refers to the picture JS, CSS and other files, the user to visit a site, in fact, most of the elements are pictures js, CSS, etc., these static files will be cached by the client's browser to the local computer, the purpose is not to go to the server on the next request to download, so that speed up, Improves the user experience. But these static files can not always be cached, he has some timeliness, then this is the expiration time.

The configuration is as follows:

<ifmodule mod_ Expires.c>    expiresactive on    expiresbytype image/gif    "Access plus 1 days"     ExpiresByType image/jpeg  " Access plus 24 hours "    ExpiresByType image/png " access  Plus 24 hours "    ExpiresByType text/css " now plus 2  Hour "    ExpiresByType application/x-javascript " now plus 2 hours "    ExpiresByType application/javascript " Now plus 2 hours "     ExpiresByType application/x-shockwave-flash  "Now plus 2 hours "    ExpiresDefault " Now plus 0 min "</IFMODULE>

Or use the MOD_HEADRS.C module to implement

<ifmodule mod_headrs.c>

#htn. Html.txt class file cache one hours

<filesmatch "\. (html|htm|txt) $ ">

Header set Cache-control "max-age=3600"

</filesmatch>

#css, js,swf class file cache for one weeks

<filesmatch "\. (css|js|swf) $ ">

Header set Cache-control "max-age=604800"

</filesmatch>

#jpg, gif,jpeg,png,ico,flv,pdf and other files cache for one year

<filesmatch "\. (ico|gif|jpg|jpeg|png|flv|pdf) $ ">

Header set Cache-control "max-age=29030400"

</filesmatch>

</IfModule>

Description: The time unit here can be days, hours or even min, two different methods, the above is used Mod_expires, and the following is mod_headers, to use these modules, you must have been supported in advance.

How to see if support, using commands :

#/usr/local/apache2/bin/apachectl-m


This article from "12350027" blog, declined reprint!

Apache Configure static cache

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.