Use. htaccess in apache to set webpage content caching (js, css, image)

Source: Internet
Author: User

Setting webpage images, css/js files, html static webpages, and even dynamic webpages to set cache time is not only to save server overhead, in more cases, users can feel "faster network speed". It is necessary to properly set the cache, especially images, css, js, txt, static html files, and other infrequently changed files.

Add the following code to the. htaccess file to set the webpage cache time. If this function is temporarily disabled during development and debugging.

The code is as follows: Copy code

<FilesMatch ". (flv | gif | jpg | jpeg | png | ico | swf | css | txt | pdf) $">
Header set Cache-Control "max-age = 36000"
</FilesMatch>

This code is set to cache for 10 hours and can be modified as needed.

Note: Before making any changes, back up the website Data Domain. htaccess file.

Save the edited file. The value of the "max-age" parameter in the code is 36000 (seconds), so the image cache and Flash content are cached in the browser for 10 hours.

Related Article

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.