Simple Apache Expires Setup via .htaccess

Last Updated on November 28, 2014 EST by Jordan

If you’ve used Google Page Speed then you’ve probably seen “Leverage browser caching” as one of the items on the Medium Priority list. And it’s a real simple fix if you’re running Apache. Just create or edit your .htaccess file for the site you want to enable it on and input the following.

<IfModule mod_expires.c>
    ExpiresActive on
    ExpiresByType image/gif "access plus 1 years"
    ExpiresByType image/jpeg "access plus 1 years"
    ExpiresByType image/png "access plus 1 years" 
    ExpiresByType text/css "access plus 1 years"
    ExpiresByType text/js "access plus 1 years"
    ExpiresByType text/javascript "access plus 1 years"
    ExpiresByType application/javascript "access plus 1 years"
    ExpiresByType application/x-javascript "access plus 1 years" 
    #ExpiresDefault "access plus 1 days"
</IfModule>

And Viola, you’re now telling Web Browsers not to grab Images/CSS or Javascript unless otherwise required.


Did you like this article?