Search code examples
.htaccesscachingbrowser-cachepagespeed

Leveraging Browser Caching Not Working


I know my htaccess file is being read correctly by Google Pagespeed (it correctly reads I have enabled compression, and when I delete the file it says I have not enabled compression), but it is not able to read that I have enabled browser caching. I have the following bit of code in my htaccess file. Why is it not working?

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

Thanks!


Solution

  • You have to enable enable mod_expires. Type this command and restart apache server:

    sudo a2enmod expires
    Enabling module expires.
    Run '/etc/init.d/apache2 restart' to activate new configuration!