In this web tutorial I will explain how you can use .htaccess file to leverage browser caching in your website, So that user which already access your website can get fast page load speed.So first we will explain what browser caching is and how it help us and then we will see how we can leverage browser caching using .htaccess file.
Why Browser Caching?
Browser caching store bandwidth of your server and make the page load fast. Also it can serve to user very fast without refreshing all contents of your page/website.
How to Enable Browser Caching?
The most common method of enabling browser caching is to use .htaccess file present in the root directory of your website or server.we insert some code to the .htaccess file to enable browser caching.Some of the CMS like wordpress use plugins for the browser catch and other type of catch.But if you don’t want to use plugin or if you don’t use a CMS where caching plugin is not help full or not developed then you can use manual insert the .htaccess code to avail browser caching or any other type of caching.
The code below tells browsers what to cache and how long to “remember” it. It should be added to the top of your .htaccess file. Here is the code to leverage browser caching htaccess.
## EXPIRES CACHING ##
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 application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
## EXPIRES CACHING ##
This .htaccess code will Leverage browser caching for your website and will make it much fast so you can get a faster load time and a batter ranking for your site in search engines.
you can also use the above code to leverage browser caching in WordPress .htaccess, just copy it and paste it in the WordPress public_html .htaccess file.
leverage browser caching plugin:
Below are few plugins which you can use inside WordPress to leverage browser caching.
These plugins can be use to leverage browser caching inside WordPress, the most used plugin in WordPress in the above list is w3 total cache and it have a lot of options.
If you have know more efficient method for browser caching than please share that in the comments.