Why does Cloudflare slow down the site by increasing TTFB?

Greetings to you!

Input data: My site is located in Moscow, and I use Cloudflare Pro with all the acceleration and optimization functions.

I am using LiteSpeed + MariaDB 10.5, and everything works very fast. Pages weigh a maximum of 50 KB.

When accessing the server directly from Estonia, the source server in Moscow delivers the HTML page in 100-200 milliseconds (time to first byte).

I also use Cloudflare Pro with all the website acceleration and optimization features. The site code is written in PHP 7.2 by the senior developer.

I repeat, the site loads in 100-200 milliseconds when accessed from Europe WITHOUT Cloudflare.

Traffic mainly comes from the USA, Europe, India, Brazil, Russia, and Australia.

Question: Why does the “TTFB” increase from 400 to 1200 milliseconds when connecting the website to Cloudflare?

Why is this so? Shouldn’t the CDN, on the contrary, speed up and reduce TTFB and so on?

Maybe you have encountered a similar situation and know how to solve this oddity?

Unfortunately, Cloudflare support is no longer what it was 5 years ago. Now it is an incredibly slow, bureaucratic organization. Their tech support has not been able to respond for a month after I provided all the data, including my browser HAR records.

Therefore, I am writing to the community in the hope of finding a solution to this problem.

Since Cloudflare acts as a reverse proxy, we might affect the TTFB for a site. There are a few HTTP requests that add up to the total TTFB:

  1. Cloudflare successfully negotiating a connection with your origin.
  2. Cloudflare sending a request on the connection.
  3. The origin generating a response.
  4. Cloudflare receiving the response.

Essentially, you may see a larger TTFB because we don’t send data back until after we have connected to your web server and it has responded.
The difference is usually no more than a few milliseconds, but more details on Cloudflare and TTFB can be found here:
Are you measuring what matters? A fresh look at Time To First Byte

You can use Cloudflare Observatory to run tests and check the real user monitoring (RUM) data.
This page can help you understand the results of the tests.

If you’re seeing the TTFB is unusually high on dynamic resources (CF-Cache-Status is not HIT, see Cloudflare cache responses):

  1. Follow the customize the cache guide to make sure that any resource that can be cached appropriately is cached. You can review the Cache Analytics on the Cloudflare Dashboard to check for cache performance and potential improvements.
  2. Make sure your origin web server is performing well: you might need to check with your website administrator or hosting provider.

If you’re seeing a high TTFB on cached resources (CF-Cache-Status is HIT) or on resources hosted on Cloudflare (through Workers or Pages for example), please share the following information with us so we can further investigate:

  • The output from running the following command:
curl -svo /dev/null -w "Connect: %{time_connect} \n TTFB: %{time_starttransfer} \n Total time: %{time_total} \n" https://<HOSTNAME>
  • The output of the following webpage in a browser: http://thedomainname.com/cdn-cgi/trace
  • A HAR file demonstrating the issue from your browser
  • An MTR or traceroute to <HOSTNAME> from an affected device
  • Any information from any other tools showing the high TTFB value: please provide details on how did you measure or where did you get the information

Besides what @jochen wrote, also check out Improving Time To First Byte (TTFB) With Cloudflare :slight_smile:

1 Like


The comments by @jochen and @eva2000 provide useful tips/guidance.

We recently implemented ‘smart prefetching’ on our website (runs on Cloudflare Workers Sites), using Speculation Rules (something new in Chrome browser).

I wrote a long article about what SR is, how we used it and the impact on TTFB: How to Improve TTFB on Cloudflare with Speculation Rules.

1 Like

Great article - had read it when it came out :slight_smile: Reminds me of https://instant.page/ which I use :slight_smile: Speculation Rules will be the evolution of that :smiley:

Thanks :smile:

instant.page is cool and surely its maker will leverage the Speculation Rules API once it has wide browser support.

What I especially like about Speculation Rules is that you can easily specify which (internal) links to prefetch and how eager the browser should do the prefetching.
Also, and importantly, there is no need to register event listeners etc in JS … all that is handled by the browser natively.

1 Like