Leverage browser caching

A web browser need to retrieve many resources from server (i.e. HTML files, CSS file, JS files, text, images etc.) in order to load a website. Web Cache is the technology used in web browsers and software applications to ‘temporally store’ or ‘remember’ visited web page resources on local disc. This temporarily stored data is called ‘ Web Cache’ or ‘HTTP Cache‘ And when you visit the same website or webpage again. This time web browser downloads only updated content from website and combines it with ‘temporally stored’ data of that same website. Due to this web cache help to reduce bandwidth usages, server loads etc. Therefore, Leverage Browser Caching became important to load your web pages faster.

Where I can enable this feature?

It’s basically an Apache module and this should be enabled by adding specific code to the Apache configuration file. Most of the users have only user level access to the server. That’s the important of this post. Here I’m listing a code which can be added to the .htaccess file to enable this feature. The .htaccess is located in the public folder of your website.

Here is the code to add:

## EXPIRES CACHING ##
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 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 2 days"
## EXPIRES CACHING ##

By using above code, the main static contents such as images, CSS, PDF’s, JS, etc will be cached in web browser in order to produce faster loading times in the future.

That’s it 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

Social media & sharing icons powered by UltimatelySocial