Use. htaccess for browser picture file caching

Source: Internet
Author: User

For the image of the site, each time you open the page to re-download the picture, slow not to say, but also a waste of traffic. Then you need to use the cache to force the browser to cache the picture file

Cache files, ask the website to visit several degrees, reduce traffic consumption, now provides 2 cache code

Open the. htaccess file, and write the following code

Method one: Unified cache duration

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

Method two: Cache duration by different file types

<ifmodule mod_expires.c>expiresactive onexpiresbytype image/jpg "Access 1 Year" Expiresbytype image/jpeg "Access 1 Year ' Expiresbytype image/gif ' access 1 year ' Expiresbytype image/png ' access 1 year ' Expiresbytype text/css ' access 1 month ' Expiresbytype text/html "Access 1 month" Expiresbytype application/pdf "Access 1 month" Expiresbytype Text/x-javascript " Access 1 Month "Expiresbytype Application/x-shockwave-flash" Access 1 month "Expiresbytype Image/x-icon" Access 1 Year " ExpiresDefault "Access 1 month" #默认文件缓存时长, with caution </IfModule>

Attention:

ExpiresDefault "Access 1 month", the default file cache length, use caution, otherwise your methods will be invalidated, such as record browsing volume, you must F5 refresh the page to

Extended reading:

How to create the. htaccess file?

Download a. htaccess file

Original address: http://cssteach.com/show-20-113.html

Use. htaccess for browser picture file caching

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.