Use. htaccess to cache browser image files. _ PHP Tutorial

Source: Internet
Author: User
Use. htaccess to cache browser image files ,. Using. htaccess to cache browser image files. for image websites, you need to download images again every time you open the page. this is a waste of traffic. In this case, you need to use. htaccess to cache browser image files,

For image websites, you need to download images again every time you open the page. this is a waste of traffic. Cache is required to force the browser to cache image files.

Cache Files, question the number of website renewals, reduce traffic consumption, now provides the cache code in 2

Open the. htaccess file and write the following code:

Method 1: uniform cache duration

 
  Header set Cache-Control "max-age=2592000"
 

Method 2: cache duration based on different file types

 
  
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" # default file cache duration, use with caution
 

Note:

ExpiresDefault "access 1 month", default file cache duration, use with caution, otherwise some of your methods will fail, such as record the page views, you must F5 refresh the page to be able

Additional reading:

How to create a. htaccess file?

Download the. htaccess file

Address: http://cssteach.com/show-20-113.html

For image websites, you need to download images again every time you open the page. this is a waste of traffic. In this case, you need to use the 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.