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.

When PageSpeed Insights complain about 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.

Open 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 ##

ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"

## EXPIRES CACHING ##

Save your .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.

Note: Autoptimize

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.

Stay Updated

Stay Updated

Subscribe to our weekly newsletter and stay updated with rockingWP's latest news and interesting links from the WordPress community.

Thanks for subscribing to the rockingWP weekly newsletter, YOU ROCK!

Stay tuned and keep an eye on your inbox. Please, don't forget to confirm the subscription validation link Mailchimp sent you.

 

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.


  1. After first backing your .htaccess file up of course 
  2. Cloudflare is a great solution. but due to how its system infrastructure is setup Cloudflare’s free caching solution tends to have a rather slow Time to First Byte