使用.htaccess进行浏览器图片文件缓存,
使用.htaccess进行浏览器图片文件缓存,
对于图片类网站,每次打开页面都要重新下载图片,慢不说,还非常浪费流量。这时就需要用到缓存,强制浏览器缓存图片文件
缓存文件,提问网站访问数度,减少流量消耗,现提供2中缓存代码
打开.htaccess文件,写入下面代码
方法一:统一缓存时长
<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|txt|swf|pdf|swf|js)$"> Header set Cache-Control "max-age=2592000" </FilesMatch>
方法二:按不同文件类型缓存时长
<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>
注意:
ExpiresDefault "access 1 month" ,默认文件缓存时长,慎用,否则你的有些方法将失效,比如记录浏览量,必须F5刷新页面才可以
扩展阅读:
如何创建.htaccess文件?
下载.htaccess文件
原文地址:http://cssteach.com/show-20-113.html

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The method of customizing resize symbols in CSS is unified with background colors. In daily development, we often encounter situations where we need to customize user interface details, such as adjusting...

Using locally installed font files in web pages Recently, I downloaded a free font from the internet and successfully installed it into my system. Now...

Realize the gap effect of card coupon layout. When designing card coupon layout, you often encounter the need to add gaps on card coupons, especially when the background is gradient...

The problem of container opening due to excessive omission of text under Flex layout and solutions are used...

How to solve the display problem caused by user agent style sheets? When using the Edge browser, a div element in the project cannot be displayed. After checking, I posted...

Why do negative margins not take effect in some cases? During programming, negative margins in CSS (negative...

How to obtain dynamic data of 58.com work page while crawling? When crawling a work page of 58.com using crawler tools, you may encounter this...

Implementing responsive layouts using CSS When we want to implement layout changes under different screen sizes in web design, CSS...
