For picture websites, pictures must be re-downloaded every time the page is opened, which is not only slow, but also a waste of traffic. At this time, you need to use caching to force the browser to cache image files
Cache files, ask how many times the website has been visited, and reduce traffic consumption. We now provide 2 caching codes
Open the .htaccess file and write the following code
Method 1: Unified cache duration
<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|txt|swf|pdf|swf|js)$"> Header set Cache-Control "max-age=2592000" </FilesMatch>
Method 2: Cache duration according to different file types
<IfModule mod_expires.c> ExpiresActive On ExpiresByType 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" #默认文件缓存时长,慎用 </IfModule>
Note:
ExpiresDefault "access 1 month", the default file cache duration, use with caution, otherwise some of your methods will be invalid, such as recording page views, F5 is required to refresh the page
Extended reading:
How to create a .htaccess file?
Download the .htaccess file
Original address: http://cssteach.com/show-20-113.html
The above introduces the use of htaccess for browser image file caching, including the content of htaccess. I hope it will be helpful to friends who are interested in PHP tutorials.