Leverage Browser Caching in WordPress to Achieve A Higher PageSpeed Insights Score
If you manage WordPress, chances you are looking to improve the performance of your websites are rather large. Most often WordPress users will implement caching solutions such as WP Super Cache, W3 Total Cache, WP Rocket and Autoptimize.
Some WordPress users, webmasters, site owners may even care about Google PageSpeed Insights – most likely because they read somewhere that it may increase their SERP rankings and thus traffic.
Especially when running WP Super Cache, by Automattic, with or without Autoptimize, PageSpeed Insights will highly likely recommend to leverage browser caching.
The otherwise excellent WP Super Cache plugin does not offer any option to leverage browser cache thus in order to score highly, above 90, in Google’s PageSpeed score we need to find another way. Several other caching plugins do implement browser caching though, but also for WP Super Cache users it is easy to configure.
Leverage Browser Caching with .htaccess
All that’s required to activate browser caching in WordPress is the addition of some simple lines to your
.htaccess file in the root folder of your WordPress installation1, in your FTP client or cPanel’s file manager, and add the following lines of code above the
# BEGIN WordPress section.
## EXPIRES CACHING ##
.htaccess file and empty the WP Super Cache. After this you may want to rebuild the cache for your site with WP Super cache’s preloader, if you want to quickly recreate your cached sites, pages again.
The PageSpeed Tools will now be satisfied about the found browser caching. Browsers will now cache images for a duration of 1 year, as instructed by the code above, and 1 month for other files.
The Autoptimize plugin, by Frank Goossens, offers HTML minification.
Note About PageSpeed Ratings
While fast loading websites are important, personally we do not truly care about scoring 90 or higher in the PageSpeed Insights.
First and foremost we believe that having solid, fast hosting is primordial, and secondly we focus on the so-called Time to First Paint, which is a benchmark about how fast sites start loading.
Technically it is easy – and common – to have fast loading sites, but still needing to wait for several, many seconds before a site actually start rendering the content. Examples of this often occur because of poor caching implementation, DNS issues, slow SSL certification by third-party integrations, websites with much content using CloudFlare’s free caching platform2, and also websites which suffer in performance due to poor security solutions which slow down the Time to First Paint because of the many checks before the server actually does deliver data. Websites with many, many
.htaccess rules may also suffer a performance hit.
All this can sometimes lead to absolutely slow websites, websites taking 6-10 seconds before they actually start loading. But when they finally load, they load blazingly fast. Some of these sites may even have high PageSpeed score despite abysmal Time to First Paint.
We personally do implement caching solutions on all our websites, but we do not focus on caching for the sake of Google’s PageSpeed Insights score.