How to set browser-caching expiration time for css files?

+1 vote
116 views
asked Jan 31, 2014 by Thomas
I evaluated my website with Google insights and the score of my website was 72/100. The recommendation I got was to set expiration to the CSS files. Could you advise me how I can do this?

1 Answer

+1 vote
answered Jan 31, 2014 by Janakiram Raghumandala
 
Best answer

You need to modify .htaccess file. 

This is the file you have to specify the browser cache duration, as shown below. I have also given recommended values for each of the file types. Images are certainly cached for 1 year, since we rarely edit an image file. 

But if you hit "Refresh" button on your browser, the browser will flushed all the cached content w.r.t. that page and it reloads the new stuff. This is useful especially during the development of your website.

 

## EXPIRES CACHING ##

<IfModule mod_expires.c>
ExpiresActive On
## IMAGES ##
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/x-icon "access 1 year"
 
## SOURCE CODE AND OTHER CHANGING STUFF ##
ExpiresByType text/html "access 1 month"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##
...