Apache enable browser caching

Apache is a wonderful web-server you can do just about anything with it but there are some tweaks you can implement to make your webpage faster.

Enabling browser caching on your server sends a message to the browser to you guessed it cache some of the page elements for next time. This results in faster page load times which helps SEO scores and user experience.

Here is how to implement it

first thing you need to make sure the following modules are enabled

headers
expires

to enable them run the following command

sudo a2enmod headers
sudo a2enmod expires
sudo service apache2 reload

 

now add the following settings in your .htaccess file

ExpiresActive on
# Set the default expiry times.
ExpiresDefault "access plus 2 days"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType text/css "now plus 1 month"
ExpiresByType image/ico "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 month"
ExpiresByType text/html "access plus 600 seconds"
</IfModule>

 

this will enable Apache to tell the browser to cache aspects of the page for 1 month

 

 

Liked it? Take a second to support Sean Mancini on Patreon!

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.