简体   繁体   English

如何缓存png、ico、jpeg

[英]How to cache png,ico,jpeg

How can I cache the image on my website for 2 days with the htaccess so:如何使用 htaccess 在我的网站上缓存图像 2 天,以便:

1 x 60 x 60 x 24 x 2 = 172800s

So I want to cache 'png, jpeg, jpg, ico, js'.所以我想缓存“png、jpeg、jpg、ico、js”。 How can I do this with the htaccess我怎样才能用 htaccess 做到这一点

You can use the mod_expires module (based in the MIME type of the file):您可以使用mod_expires模块(基于文件的 MIME 类型):

<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault A300

# png, jpeg, jpg, ico, js expire after 2 days
ExpiresByType image/gif A172800
ExpiresByType image/png A172800
ExpiresByType image/jpg A172800
ExpiresByType image/x-icon A172800
ExpiresByType application/x-javascript A172800
</ifModule>

Or the mod_headers module (based in file extension):或者mod_headers模块(基于文件扩展名):

<ifModule mod_headers.c>
ExpiresActive On

# png, jpeg, jpg, ico, js expire after 2 days
<filesMatch ".(gif|png|jpg|jpeg|ico|js)$">
Header set Cache-Control "max-age=172800"
</filesMatch>
</ifModule>

This last one gives you more options, like force no-cache, etc.最后一个为您提供了更多选项,例如强制无缓存等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM