How can i add cache control code to htaccess?

坚强是说给别人听的谎言 提交于 2019-12-12 04:57:35

问题


How can I add cache control code to .htaccess?

My site is slow and I found 35 static components without a far-future expiration date.

How can I add expiration data for that? I was informed that this could be done in the .htaccess file but I don't know how.


回答1:


You can use something like this:

# Cache Files
<filesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=604800, public"
</filesMatch>

This caches any file ending with ico|pdf|flv|jpg..... for 604800 seconds, which is one week, you can change that number to cache for however long you feel you need.



来源:https://stackoverflow.com/questions/17669513/how-can-i-add-cache-control-code-to-htaccess

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!