Fix: Leverage browser caching not enabled

User Avatar
πŸ‘€ admin
πŸ”΄ Admin
✍️ The most important thing in the world is to not be alone.
⏳ Last active: 15 Apr 2025 at 16:01
πŸ“… Created: 11 Feb 2021 at 12:07
πŸ‘€ Viewed: 49 times
βœ‰οΈ Send Email

Have you ever tested your website for speed with googles website test tool? Then you have seen the error: Leverage browser caching not enabled. To fix this you need to enable and configure mod_expires in Apache web server. This will make your website faster and better and meet the requirements of google website page speed.


What does this module do? The module controls the setting of the Expires HTTP header and the max-age directive of the Cache-Control HTTP header in server responses. The expiration date can set to be relative to either the time the source file was last modified, or to the time of the client access.

These HTTP headers are an instruction to the client about the document's validity and persistence. If cached, the document may be fetched from the cache rather than from the source until this time has passed. After that, the cache copy is considered "expired" and invalid, and a new copy must be obtained from the source.

First we need to enable the mod in the terminal:


# In the console enable mod expires

a2enmod expires

Then we restart apache2


# Restart Apache web server

service apache2 force-reload

Our next step is going to be to edit 000-Default.conf


# Edit 000-Default.conf in /etc/apache2/sites-available/

pico /etc/apache2/sites-available/000-default.conf


Between the lines <VirtualHost *:80> and </VirtualHost> add the following code below:


# Add between the lines &lt;VirtualHost *:80&gt; and &lt;/VirtualHost&gt;

&lt;IfModule mod_expires.c&gt;

ExpiresActive on

ExpiresByType image/jpg "access plus 60 days"

ExpiresByType image/png "access plus 60 days"

ExpiresByType image/gif "access plus 60 days"

ExpiresByType image/jpeg "access plus 60 days"

ExpiresByType text/css "access plus 1 days"

ExpiresByType image/x-icon "access plus 1 month"

ExpiresByType application/pdf "access plus 1 month"

ExpiresByType audio/x-wav "access plus 1 month"

ExpiresByType audio/mpeg "access plus 1 month"

ExpiresByType video/mpeg "access plus 1 month"

ExpiresByType video/mp4 "access plus 1 month"

ExpiresByType video/quicktime "access plus 1 month"

ExpiresByType video/x-ms-wmv "access plus 1 month"

ExpiresByType application/x-shockwave-flash "access 1 month"

ExpiresByType text/javascript "access plus 1 week"

ExpiresByType application/x-javascript "access plus 1 week"

ExpiresByType application/javascript "access plus 1 week"

&lt;/IfModule&gt;

After this we have to restart again:


# Restart Apache web server

service apache2 restart

If all is done correctly the error is going to disappear.
We hope you enjoyed thisΒ article. if that is so please rate this page with the stars bellow and subscribe to ourΒ YouTube channel.

If you want to comment: Login or Register