Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set expiration on CSS, JS and Images?

I have recently analysed my website with pagespeed addon on firebug. It suggested me to set expiration on CSS, JS and image files.

I am wondering, how do I do this?

like image 863
KoolKabin Avatar asked Nov 10 '10 05:11

KoolKabin


2 Answers

This is the one I use to fix the exact same thing when I ran the PageSpeed Addon:

<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">     Header set Cache-Control "max-age=604800, public" </FilesMatch> 

This goes into your .htaccess file.

Read up on this page for more information about how to set cache for additional file types and/or change the cache length:

http://www.askapache.com/htaccess/apache-speed-cache-control.html

like image 188
Jay Avatar answered Sep 18 '22 18:09

Jay


i would like to add this solution for those searching for it....

its also works great...using .htaccess

https://webmasters.stackexchange.com/a/5275/37765

 <FilesMatch "(?i)^.*\.(ico|flv|jpg|jpeg|png|gif|js|css)$">   ExpiresActive On   ExpiresDefault A2592000  </FilesMatch> 
like image 27
Mohammed Sufian Avatar answered Sep 19 '22 18:09

Mohammed Sufian