TTFB speed is relative so if your origin web server is located further away from test location then TTFB is higher and vice versa. Also TTFB can be impacted by client side factors like the speed and CPU power of the client device connecting to the server or even what the client device is doing in background (like watching a video).
For relative distance factors, this is due to 2 reasons:
-
Cloudflare not caching HTML content by default (see below). So for optimal TTFB speed, you want your origin real web server to be hosted in a location closest to your majority traffic visitors and then put Cloudflare in front. For instance, my forums has 50% US visitors 40% Asian visitors and 10% Oceania. So my optimal geographic location for my origin is US West Coast as it sits in middle of US, Europe and Asian so equal round trip times for majority of visitors. Cloudflare cache certain static content Default Cache Behavior · Cloudflare Cache (CDN) docs but not dynamic/static generated html itself by default (which is what Webpagetest.org TTFB is testing for). But you can tell Cloudflare to cache dynamic/static generated html content to some extent depending on Cloudflare plan you’re on via cache everything page rule but have to be careful to only do this for static html content and not dynamic html content (otherwise you would cache private logged in user content).
-
The higher the Cloudflare plan you go, the better the routing and ISP/network peering gets. Cloudflare refers to this on their Plan’s page Our Plans | Pricing compare all features link display as Network Prioritization. Due to varying ISP costs around the world Bandwidth Costs Around the World. The latest example is Cloudflare’s Guam datacenter deployment and peering and it’s impact on network latencies. As it may cost Cloudflare more money to serve a request from some geographic datacenters than others, financially Cloudflare can’t always route visitors to the nearest datacenter. For instance some geographical locations which historically showed such cases are India and Australia. On Cloudflare free plan visitors from India or Australia maybe routed to Cloudflare’s Singapore or Los Angeles data centers due to lower cost. As you moved up the Cloudflare plan tiers to more paid plans, the higher probability of getting routed closer to Cloudflare datacenters in the same region for such high cost countries. My experience with using Cloudflare for past 11yrs on CF Free, Pro, Business and Enterprise plans, is if you want Australian visitors routed to Cloudflare Australian datacenters, you’d need at least Cloudflare Business for higher probability of such. But for Indian visitors to be routed to Cloudflare India datacenters, you’d need Cloudflare Enterprise plan for higher probability. I say higher probability as it still isn’t guaranteed. Though over the years, the probability has gotten better as peering arrangements have improved I suspect Network performance update: Platform Week. The link at https://cloudflare-test.judge.sh/ is a good guide to how peering is for different Cloudflare plan based sites too. Only focus on the reported data center served from various plans and not the actual metrics as variance can be due to many factors - including whether or not each site on each CF plan has already implemented some of the below mentioned TTFB optimizations which will impact the reported metrics. There’s also an extended explanation at Explanation · judge2020/cloudflare-connectivity-test Wiki · GitHub
Users have also reported for Vietnam visitors, they also maybe routed elsewhere like Hong Kong or Singapore due the above mentioned peering agrement/costs Cloudflare at vietnam - #5 by soldier_21. This seems to be the case even for Cloudflare Enterprise.
As it relates to TTFB improvements:
-
Head Requests and Set-Cookie Headers · Cloudflare Cache (CDN) docs
-
Using CDN Cache control to fine tune CDN caching from your origin CDN-Cache-Control: Precision Control for your CDN(s)
-
Ensure your origin web server supports Brotli content-encoding responses. Soon Cloudflare will support the native transmission of Brotli compressed data from your origin servers. Currently, Cloudflare forwards all HTTP requests to the origin with the following header:
Accept-Encoding: gzip
. Over the coming weeks, Cloudflare will be transitioning to the following header to allow the origin to send Brotli compressed content to Cloudflare:Accept-Encoding: gzip, br
. Full details on Cloudflare blog at All the way up to 11: Serve Brotli from origin and Introducing Compression Rules -
Caching Anonymous Page Views on CF Business plan or CF Workers custom caching you can properly distinguish between logged in users versus guests so tell Cloudflare via bypass cache on cookie page rules to only cache for guests the dynamic/static generated html content and bypass cache for logged in users. For Cloudflare Workers caching How the Cache works · Cloudflare Workers docs you can implement and write your own Cloudflare Work based guest full HTML page caching proxy to do the same on any Cloudflare plan - Free and Pro included. Basic examples of using CF Worker’s Cache API to do such without the bypass cache on cookie logic that you need to add at Using the Cache API · Cloudflare Workers docs or using fetch method caching at Cache using fetch · Cloudflare Workers docs. Cloudflare Business plan’s bypass cache on cookie page rule though is fixed cost caching versus Cloudflare Worker based caching having variable costs Pricing · Cloudflare Workers docs. So on Cloudflare Bundled Worker plan would be $5/month with 10m requests included and overages $0.50/million. So you would need to push past 390 million CF Worker cached requests to = $200 per month CF Business plan price. The same can be done if you’re using Cloudflare’s Wordpress plugin with Cloudflare Automatic Platform Optimization (APO) caching for $5/month Introducing Automatic Platform Optimization, starting with WordPress and Welcome · Cloudflare Automatic Platform Optimization docs and subsequent blog tagged updates to APO Automatic Platform Optimization - The Cloudflare Blog. From September 27, 2022 onwards, there’s also now Cloudflare Cache Rules which include bypass cache on cookie support for all Cloudflare plans. See blog post at Introducing Cache Rules: precision caching at your fingertips
-
Then on CF Business plan you have access to Railgun which allows you to accelerate dynamic generated html content for the logged in users Railgun™. Update: Railgun is now deprecated Cloudflare is deprecating Railgun
-
Then there’s also Argo for optimising the routing to your origin as well Argo Smart Routing | Traffic Acceleration
-
The latest performance option is Tiered Cache Tiered Cache · Cloudflare Cache (CDN) docs and Improving Origin Performance for Everyone with Orpheus and Tiered Cache which use to be a Cloudflare Enterprise option but now is available on all paid plans including Pro and Business.
-
Cloudflare Enterprise plan users also now have Regional Tiered Caching to further improve cache hit rates Reduce latency and increase cache hits with Regional Tiered Cache
-
A newer development now is also Cloudflare opening up SaaS for everyone Announcing Cloudflare for SaaS for Everyone, so you can now on any Cloudflare plan, technically extend your Cloudflare feature, security and performance sets to domains not on Cloudflare. This has been great as I can now extend some Cloudflare Enterprise or Business features to domains not on those plans too or not even on Cloudflare!
-
There’s also Cloudflare’s Automatic Signed Exchanges Improve site load times and SEO with one-click support for Signed Exchanges on Google Search. In theory it’s meant to improve Largest Content Full paint by improving TTFB. But in it’s current state of implementation it has limited benefits due to it only being for Android mobile devices right now and not all Google search result listings getting SXG cache/prefetch being triggered. Google feature snippet listings on Google search also do not get SXG cache/browser prefetch support right now. Only like top 1 or 2 search results listed on Google search would benefit and SXG cached version is slower for pages which don’t get Google Chrome Android browser’s SXG cache prefetch (pages not listed or ranked in top position). I wrote a detailed blog about Cloudflare SXG caching and Android Chrome cache prefetch - including benchmarks at https://blog.centminmod.com/2021/10/13/2511/testing-page-speed-with-cloudflare-automatic-signed-exchanges-google-search-cache/
Older thread cover some of the page speed metrics at Performance Tutorials - Google PageSpeed & Webpagetest.org. Another guide I wrote outlined for Google Lighthouse/Pagesped Insight for my Centmin Mod community users which is same engine GTMetrix has switched to at https://community.centminmod.com/threads/google-page-speed-insights-and-google-core-web-vital-metrics.20735/.
To fully optimise you need to optimize 3 segments.
-
segment 1 - connection between visitor and CF edge server i.e. CDN cache/CDN cache control, Cache Rules, WAF, Firewall, Page Rules, Mirage, Polish webP, HTTP/2, HTTP/3, CF Workers (i.e. custom/advanced caching) etc. Cloudflare CDN level caching effectively reduces your origin server resource usage loads for CPU/Memory etc as request load is offloaded to Cloudflare CDN edge servers in an Anycast manner to the closest CF datacenter to the visitor.
-
segment 2 - connection between CF edge server and your origin i.e. TLSv1.3 origin server support, Argo, Railgun, Full SSL/ECDSA SSL certificates origin served, pre-compressed/dynamically compressed gzip and/or brotli encoded asset served from origin, Tiered Caching and Cache Reserve eventually once out of Beta (right now TTFB ends up slower with Cache Reserve beta enabled).
-
segment 3 - your origin server’s performance/optimisations i.e. web server, PHP, MySQL server optimisations and server hardware specs. Origin server side caching, PHP Zend Opcache caching, MySQL’s various buffer caching and various other origin server side caching can also be used.
Cloudflare can only help for segments 1 & 2 for cached guest/non-logged based visitors will easily scale. Now for Cloudflare CDN cache miss/bypass and logged in user for web apps like forums/wordpress, performance will be determined by segment 3. Which is the default with Cloudflare as dynamically generated HTML pages aren’t cached by default so cache miss means, whatever performance you have is measuring your origin server’s response time.