What is Leverage Browser Caching?
Leverage Browser Caching stores data locally so that future requests for that data can be served faster. A web browser needs to retrieve many resources such as HTML, CSS, JS, text, images, etc. in order to load a website. Web Cache is the technology used in web browsers and software applications to temporally store visited web page resources on a local disc. This temporarily stored data is called “Web Cache” or “HTTP Cache”.
By having this data stored on your visitor’s local hard drive, your webpage will be loaded much faster on their next visit. This is because the data will be pulled directly from their computer instead of having to travel through the internet from a web server.
If you have ever tested your website on Google Page Insights, GTMetrix or Pingdom you might have seen this optimization recommendation. Leverage Browser Caching is an important optimization that will speed things up for your return visitors.
How to Setup Leverage Browser Caching
To set up Leverage Browser Caching in WordPress, you will need to set an expiry date or a maximum age in the HTTP headers for static resources in your .htaccess file. This will instruct the browser to load previously downloaded resources from a local disk rather than over the network and how long to use these resources.
There are plugins out there that can enable Leverage Browser Caching for you, but I like to limit the number of plugins that I use to avoid problems and conflicts. Another reason you don’t really need a plugin for this is that enabling Leverage Browser Caching is extremely easy to do yourself. In the steps below, I will show you how to do this without a plugin.
Step 1: Locate your .htaccess File
Login to your cPanel and go to the File Manager. The .htaccess file is hidden by default. You will need to find the settings icon on the top right and change the option to show hidden files.
After you enable Hidden Files (dotfiles) you should be able to find the .htaccess file located in the your public_html folder.
Step 2: Edit your .htaccess File
Right click the .htaccess file and choose edit. Copy and paste the code below inside the file:
Make sure you save your changes and close the file editor.
Step 3: Make Sure Everything is Working
If everything is functioning correctly, you should no longer see this listed as a recommended optimization. However, you might still have an issue with other external files that you have no control over.