Connect with us

Hi, what are you looking for?

Technology

Use Cloudflare Page Cache to Speed Up WordPress

Cloudflare has plenty to offer even to free users. I looked into some methods of improving the TTL or time to first byte as a way to speed up my website’s page load times.

I found there was Page Rule configuration in Cloudflare that can be setup to improve the speed through caching.

Login to Cloudflare and navigate to the Page Rules page. First create a new rule as shown below:

Page rule for all content
Use this rule to cache all content

Setup Page Rule for Bypass

With the above rule all content on the website should be cached. This might lead to an issue with the Dashboard and WordPress backend. This can be fixed by adding another Page Rule like below:

Page rule for WordPress Admin exclusion
Page rule to exclude the WordPress Admin and Backend pages

Complete View of Page Rules

When completed the list of page rules should look like below and order matters as the Admin bypass needs to be above the cache everything rule for it to work properly.

Cloudflare Page Rules
Cloudflare Page Rules Final Example

Set Browser Cache TTL Settings

One last setting to set before closing Cloudflare is the Browser Cache TTL setting which is found on the Caching page under Configuration. This needs to be set to “Respect Existing Headers” otherwise HTML content will be cached and users might not see updated posts or page updates.

Update htaccess file

A side effect could be that the WordPress Admin bar might disappear and this can be fixed by copy and pasting the below code snippet into the bottom of the .htaccess file.

# Begin Cloudflare headers for page cache
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} !/wp-admin [NC]
RewriteCond %{HTTP_COOKIE} !"wordpress_logged_in"
RewriteRule ^.*$ - [ENV=LONGCACHE:true]
<IfModule mod_headers.c>
Header unset Pragma env=LONGCACHE
Header unset Expires env=LONGCACHE
Header set Cache-Control "max-age=600" env=LONGCACHE
</IfModule>
</IfModule>
# End Cloudflare headers for page cache
Click to comment

Leave a Reply

Your email address will not be published.

You May Also Like

Docker

Setting up NGINX with a free Let’s Encrypt SSL certificate is a breeze using Docker and the container maintained by Linuxserver.io. The default setup...

Plex

Plex updated it’s support of collections at the end of 2017 by letting the user choose to group movies in a collection ie. Star...

Linux

Configure the TP-Link AX50 router so that it can be shared between both Windows and Linux. The router has USB sharing built into the...

Docker

In a prior post I detailed how to backup a SQL database from a MariaDB Docker container. Since I also have a few Docker...

Copyright © 2021 Carl Peterson. Theme by MVP Themes, powered by WordPress.