Table of content
What is leverage browser caching?
Also Read: Headless CMS vs a Traditional CMS
How does the leverage browser caching method work in WordPress?
Whenever a WordPress user tries to access a certain domain, a lot of processes begin to perform in the background. Whatever data composes your website will be transmitted to the web browser of the user. This will make the browser visible to the users. Some of these data include stylesheets, images, scripts, content and many more. The steps which must be followed in order to move the data to the user’s browser from the website’s server has been mentioned below:
- The user will have to type the URL of the website in his browser.
- The browser will send a request to the server where the website has been hosted
- The server will collect all the data and send it to the uses. This is the step which requires a lot of optimisation. Otherwise, the process will become slow.
- After the data is transmitted, the browser will be able to view it on your website. This process repeats itself for all the pages of the website.
Caching method works for both software as well as website applications. There are several tools available in the market which will give you detailed information regarding whether leverage browser caching is properly working or not. All you need to do is type your website’s URL and the tool will do the rest of the work for you.
How to enable leverage browser caching for your WordPress website?
There are several methods using which you will be able to enable the leverage browser caching for your website. You need to add a few lines of codes to certain files of your website and you are good to go. Here we have mentioned some of the most basic ways using which you will be able to enable leverage browser caching:
#1. Access the files of your website
In order to access the file, you will have to log in to your website and go to the File Manager option. Here the website’s settings option is present from where you will have to turn on the hidden file option. Navigate to your website’s root directory and go to the .htaccess file. This file is mostly located in /public_html/.htaccess. If you use a custom domain, then the file is present in domainname/public_html/.htaccess. Now right-click on the file and edit its contents as per the instructions mentioned.
#2. Add the required lines of code in the .htaccess file
Once you have located the .htaccess file, you will have to add a few lines of code to it. The code has been given below:
#Customize expires cache start – adjust the period according to your needs
FileETag MTime Size
ExpiresByType text/html “access 600 seconds”
ExpiresByType application/xhtml+xml “access 600 seconds”
ExpiresByType text/css “access 1 month”
ExpiresByType application/x-shockwave-flash “access 1 month”
ExpiresByType application/pdf “access 1 month”
ExpiresByType image/x-icon “access 1 year”
ExpiresByType image/jpg “access 1 year”
ExpiresByType image/jpeg “access 1 year”
ExpiresByType image/png “access 1 year”
ExpiresByType image/gif “access 1 year”
ExpiresDefault “access 1 month”
#Expires cache end
This is the best method available to us for leverage browser caching. You will also be able to add expires headers to your code.
#3. Add cache control headers
In order to add cache-control headers, the following lines of code will have to be added to the .htaccess file:
# BEGIN Cache-Control Headers
Header append Cache-Control “public”
Header append Cache-Control “public”
Header append Cache-Control “private”
Header append Cache-Control “private, must-revalidate”
You need not have to add an expiry date to the HTTP headers and the date has already been set earlier.
#4. Turn off the Etags
Tags are entity tags. They are used to mark the newest version of all the cache files. You have already added the cache-control header to your file. You need not require the Etags anymore and so, you can switch them off to increase the loading speed of your website. You need to add the following lines of code:
Header unset ETag
Leverage browser caching by using plugins:
Adding codes to the .htacess file can at times be quite tricky. If not done properly, it will ruin the entire settings of your website. So, another easier way to enable leverage browser caching is by using different plugins. A lot of WordPress plugins are available using which you can carry out this method quickly and easily. The steps to enable leverage browser caching by use of plugins have been mentioned below:
- Download the required plugin
- Go to the Dashboard and from there, navigate to the Plugins options and click on Add New.
- Click on the Leverage Browser Caching option to install it.
- Activate your plugin and test it on your website
One such plugin is W3 Total Cache. It is a reliable plugin and has extremely fast speed. You will be able to use this plugin to enable browser cache quickly and easily. You can also add cache-control headers to your website. The plugin is extremely affordable and will greatly increase the loading time of your website.
So, this was all about leverage browser caching. We hope our article will help you to enable leverage browser caching for WordPress. Do let us know about your experience.