Home > php教程 > php手册 > body text

使用.htaccess进行浏览器图片文件缓存,

WBOY
Release: 2016-07-06 14:24:26
Original
987 people have browsed it

使用.htaccess进行浏览器图片文件缓存,

对于图片类网站,每次打开页面都要重新下载图片,慢不说,还非常浪费流量。这时就需要用到缓存,强制浏览器缓存图片文件

缓存文件,提问网站访问数度,减少流量消耗,现提供2中缓存代码

打开.htaccess文件,写入下面代码

方法一:统一缓存时长

<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|txt|swf|pdf|swf|js)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>
Copy after login

方法二:按不同文件类型缓存时长

<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>
Copy after login

注意:

ExpiresDefault "access 1 month" ,默认文件缓存时长,慎用,否则你的有些方法将失效,比如记录浏览量,必须F5刷新页面才可以

扩展阅读:

 

如何创建.htaccess文件?

下载.htaccess文件

原文地址:http://cssteach.com/show-20-113.html

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template