Now here we going to learn how to fix the leverage browser caching using .htaccess below in this you have a clear solution to fix the issue.
1. What is Leverage Browser Caching?
When visitors go to your website the request receives everything like images scripts and CSS etc., this will happen through your web server. With the help of leverage browser caching when a visitor who come back again to your website they will be getting those files from their local cache system rather than make a server request again.
2. How to Use Leverage Browser Caching Using .htaccess
Make sure ( mod_expires ) is supported by your web server, this will work only Apache based server. If you have Apache based server means you need to add the following code in the top of your .htaccess file for leverage browser caching. You can find the .htaccess file in your root directory If can’t able to see the .htaccess file here you have an article.
Want to know more about .htaccess click here.
Here you have two options One is Cache-Control Header and another one is Expires headers.
Using Expires Header you can create specific rules for different file types for all your root directory files. Here you can create a timing for your files like how long to keep the files in the local browser cache.
For client request and server response, the Cache-control is very important and it is used for HTTP header specify browser caching policies. For this, you can mention all type of files and you also set cache control maximum age.
<filesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$"> Header set Cache-Control "max-age=84600, public" </filesMatch>