In this guide, we are going to teach you how to fix the “Leverage Browser Caching warning in WordPress on a Linux-based virtual private server. Leverage Browser Caching is a warning which you may encounter if you run a speed or performance test for your website.
When you are running a speed or performance test for your WordPress website using a tool like Google PageSpeed Insights,
- for example, you may be presented with a warning message saying that you haven’t enabled browser caching for your website.
What is a Leverage browser caching exactly?
- Each time your browser loads a page, it has to download all the web resources to display that page properly.
These include resources like HTML files, CSS, JavaScript, and images. Fetching those resources over and over can be slow and expensive.
By enabling Leverage Browser Caching, you can specify the resources can be cached and by whom and for how long the resource can be cached.
And how they can be revalidated when the caching policy expires.
- Moreover, with the help of Leverage Browser Caching page load times can be significantly improved for all your returning visitors.
How do you fix the “Leverage Browser Caching” Warning in WordPress?
First, you need to find out whether your WordPress site is powered by Apache or Nginx. If you are running Apache web server on your Linux VPS, you can log in to your server and edit the .htaccess file for your WordPress website. Add the following lines:
## EXPIRES CACHING ## <IfModule mod_expires.c> ExpiresActive On ExpiresByType image/jpg "access plus 1 year" ExpiresByType image/jpeg "access plus 1 year" ExpiresByType image/gif "access plus 1 year" ExpiresByType image/png "access plus 1 year" ExpiresByType text/css "access plus 1 month" ExpiresByType application/pdf "access plus 1 month" ExpiresByType text/x-javascript "access plus 1 month" ExpiresByType application/x-shockwave-flash "access plus 1 month" ExpiresByType image/x-icon "access plus 1 year" ExpiresDefault "access plus 2 days" </IfModule> ## EXPIRES CACHING ##
If you are running Nginx on your Linux VPS, append the lines below to the server block for your WordPress website:
# Enable browser caching location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { expires 7d; }
Remember to restart Nginx so the changes can take effect:
sudo service nginx restart
After you have enable Leverage Browser Caching for your WordPress website: you may now use Google PageSpeed Insights or
- some of the other page speed tools which are available online to check the page’s status.
Also, here we have a few hand-picked guides that you must read next:
PS. If this post helped you fix the Leverage Browser Caching warning in WordPress. Share this tutorial with your hosting administrators and networking experts friends.