Last updated on March 7th, 2021 at 10:05 pm


Learning how to improve TTFB can help your speed profile of your site. Cloudflare Page Rules can help.

wordpress scrabble blocks

Image by 27707 on Pixabay

This post contains affiliate links. We may earn a commission if you purchase an item through our links. It costs you nothing and helps us to fund this blog. Please see our Affiliate Disclosure & Notification for details.

Site speed matters. Whether it’s for Google ranking or for sales conversions on your site, a slow site will kill you in every way. One of the key metrics in determining overall site speed is something known as “time to first byte” or “TTFB” for short.

If you’ve arrived here already knowing what it is and just need to know how to improve TTFB with Cloudflare Page Rules, skip to the rules below to grab them. Otherwise, keep on reading to find out what TTFB means and why it’s important.

What is Time to First Byte?

Time to First Byte or TTFB refers to how long it takes from the time your request hits a webserver until the time the very first byte of information is received from that web server. Testing tools such as GTMetrix refer to it as “server response time”.

Why is TTFB Important?

Time to First Byte is important to the overall speed of your site because it represents the time when nothing is happening. It’s wasted time that your browser could be downloading the content of the web page you’re trying to view, but didn’t.

In terms of overall speed, the TTFB adds a flat chunk to the time it takes to load your page. If your time to first byte is 2 seconds, then every single page on your website will probably take 2 seconds longer than it actually takes to download the content and render it into the web browser.

From the perspective of potential customers visiting your site, a long TTFB can make them bounce before the page even loads. People aren’t patient. If they click a link to your site or type it into their browser and nothing happens for 3 or 4 seconds, they’re hitting the back button and heading elsewhere.

What Causes a High TTFB?

An entire novel could be written on this, but we’ll keep it simple to the most common culprits.

Dynamic Content

Well, since we’re talking about WordPress sites here, that’s a bummer right? Because WordPress is pretty much centered around dynamic content.

Your blog and pages are generally built on the fly by your server when someone visits the page. Each page load sends multiple queries to the database for settings for different template parts and also grabs the content from the database and builds it into an HTML file that gets delivered to the visitors web browser upon request.

Slow dynamic content generation can be caused by large files, extra database queries, or a slow database. These could affect your server’s ability to generate the page content and convert it into that HTML.

A Cluttered Database

Over time, databases tend to get cluttered and messy. This makes queries take longer, and increases the time it takes to generate dynamic content. Using a database optimization tool can help mitigate this, but if your database is clutter because of poor design or too many heavy plugins on your site, then it might always run slow. Speaking of which…

Too Many Heavy Plugins

There is a lot of talk about how many plugins is too many for WordPress sites. And everyone seems to have their own magic number.

But all plugins are not created equal.

I’ve seen sites with over 40 plugins running just fine… maybe a little slow on the back-end, but to the average site visitor they were perfectly acceptable. I’ve also seen sites grind to halt because of a single bad plugin or conflict between 2 separate plugins.

Big heavy plugins generally include page builders such as Elementor or Beaver Builder, eCommerce plugins such as WooCommerce, and all-purpose plugins like Jetpack. If you’re using these, you want to be very careful about resource usage on your web server.

Poor Hosting

Having a well-built and optimized web server to hose your site is critical to a healthy TTFB. But the challenges are deep.

Web hosting is a constantly evolving landscape. This year’s worst performer can easily be last year’s best performer. With hosting companies changing ownership constantly, this is a highly variable element to your website’s speed and security.

One thing to always keep in mind, if you’re using cheap shared hosting, you can expect to have a slower site than if you were using an expensive VPS or dedicated server. We use reseller hosting from WebhostPython for most of our sites & client sites because they’re high-powered and, at least for now, are one of the best valued packages available.

How to Improve TTFB Using Cloudflare Page Rules

The free version of Cloudflare comes with 3 page rules per website. And fortunately, that’s just enough to set up some caching rules that should help you obtain a faster TTFB for your website.

Cloudflare page rules allow you to create custom rulesets for pages (including wildcards) to tune how your site is cached, secured, & delivered.

Here’s how we set them up.

When you log into your Cloudflare dashboard, head over to the Page Rules menu and create the following rules:

Rule #1:

*.domain.com/wp-login.php*
Cache Level: Bypass, Disable Apps, Disable Performance

Rule #2:

*.domain.com/wp-admin/*
Cache Level: Bypass, Disable Apps, Disable Performance

Rule #3:

*.domain.com/*
Cache Level: Cache Everything, Edge Cache TTL: 7 days

When you’re finished, it should look something like this:

How to Improve TTFB with Cloudflare Page Rules

What These Page Rules Actually Do

These page rules each have very specific functions and they must be configured in the order shown above. Page rules are processed in order until a rule is matched so these three rules are configured in way that tells Cloudflare to check whether the visitor is trying to log in (Rule #1) or is already logged in and managing the site (Rule #2). If neither of those rules apply, the last rule catches everything else and tells Cloudflare to deliver a fully cached page.

Rule #1: Disable Caching for the WordPress Login Page

The first rule tells Cloudflare to not cache or apply any performance (combination or minification of css/js) to the WordPress login page. If the login page is cached, you won’t be able to log in to the site.

Rule #2: Disable Caching for Everything in the WordPress Admin Directory

When you’re logged into your WordPress site, you don’t want any of the admin pages cached. Caching them will not only break your ability to work on your site, but it also opens the possibility that Cloudflare might serve those cached pages to site visitors who aren’t logged in and shouldn’t be able to see them – remember Cloudflare has no way to know whether someone is logged in to WordPress or not.

Rule #3: Cache Everything

This is where the magic happens. This rule tells Cloudflare to cache every page element, essentially allowing it to deliver the page to your site visitor without the request ever even touching your web server. The effect should provide you with a much-improved TTFB once the Cloudflare cache is primed with current content.

The Edge Cache TTL setting instructs Cloudflare to wait a certain amount of time between looking for new copies of the page on the webserver. For my sites, I usually go with 7 days.

The Results

In testing on my client sites on our reseller hosting, TTFB before applying these page rules varied between 700ms and 3000ms. It really depended on how busy the server was. Since reseller hosting usually has many hundreds or even thousands of websites on the same server, it’s highly variable.

Once we applied these page rules, our TTFB for most sites is now around 300-400ms. The only exception would be for sites that get so little traffic that the cache becomes stale before the next visitor. But as long as you have a few visitors each day, this won’t be an issue.

Limitations

If your website uses eCommerce, three page rules won’t work. This is because you also end up caching the customer-specific pages like cart & checkout. You can buy additional page rules from Cloudflare to include these pages in your cache bypass rules, but for the free version it won’t work.

If your data changes heavily and you constantly have to clear your Cloudflare cache, each clearing will result in an initial regression to your non-cached TTFB until Cloudflare’s cache gets primed again.

Final Thoughts

In this article, we talked about how to improve TTFB using Cloudflare page rules. While it’s not a replacement for good hosting, it can definitely help fill the gap.

Sharif Jameel is a business owner, IT professional, runner, & musician. His professional certifications include CASP, Sec+, Net+, MCSA, & ITIL and others. He’s also the guitar player for the Baltimore-based cover band, Liquifaction.

Subscribe to Our Mailing List

If you found the information in this post helpful, we'd love to have you join our mailing list. We promise we won't spam you, we only send out emails once a month or less.

Leave a Comment

Your email address will not be published. Required fields are marked *

You May Also Like:

This site requires the use of cookies to ensure you get the best experience.

Scroll to Top