简体   繁体   中英

How can i add cache control code to htaccess?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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