How to reduce TTFB: find where the server time goes
Nothing on a page can start before the server answers. Here’s what Time to First Byte measures, how to split it into redirects, connection and server work, and the fix for each part.
Nour9 min read · 
Make the server answer faster.
Before a browser can show anything, it has to get the first piece of the page from your server. The time that takes is called Time to First Byte, or TTFB. Nothing else can start until it’s done: not the images, not the fonts, not the main content.
TTFB isn’t one of the three Core Web Vitals, but it sits underneath all of them. A slow server answer pushes back LCP by exactly the same amount. Here’s what TTFB measures, how to find which part of it is slow, and the fix for each part.
The short answer
A good TTFB is 0.8 seconds or less at the 75th percentile of real visits. Over 1.8 seconds is poor. TTFB is the sum of a few parts: redirects, finding and connecting to the server, and the server’s own work. On most slow sites, the server’s own work is the biggest part, and the best fix is to not do it on every visit: cache the page, near the visitor.
The fastest server answer is the one the server doesn’t have to work out.
What TTFB measures
TTFB starts when the visitor clicks a link or types your address, and ends when the first byte of the page arrives. Everything in between counts:
- Redirects. If the link goes to http:// and you send people on to https://, or from the bare domain to www, each hop is a full round trip before the real request starts.
- Finding and connecting to the server. Looking up the domain (DNS), opening the connection and setting up encryption. Each step is a trip across the network, so it grows with the distance to the server.
- The server’s own work. Running your code, querying the database, calling other services and building the HTML. This is the part you control most.
- The first byte’s trip back. Again longer when the server is far from the visitor.
That’s why the same page can have a TTFB of 100ms for you and 1.5 seconds for a visitor on a phone in another country. Distance, network and a cold cache all add up.
Find the slow part
- 01Start from real visits. Check TTFB per page and per country. A page that’s slow everywhere points at the server’s work. A page that’s only slow far away points at distance and caching.
- 02Look at the request in Chrome. Open DevTools, then the Network tab, reload, click the page’s first request and open Timing. It splits the time into redirect, DNS lookup, connection, SSL and “Waiting for server response”. The waiting part is the server’s own work.
- 03Ask the server to report its steps. Add a Server-Timing header with the time your app spent on each step, like db;dur=420, render;dur=180. DevTools shows it in the same Timing tab, and monitoring tools can collect it from real visits.
- 04Compare cached and uncached. Load the page twice. If the second load is much faster, your cache works but too few visitors hit it. If both are slow, the page isn’t cached at all.
Redirects
Redirects are the cheapest fix, because often nobody needs them.
- Link to the final address. Make sure your own links, ads, emails and social profiles use the exact address the page ends up on, with https and the right www.
- Avoid chains. http to https to www to a trailing slash is three trips. Send old addresses straight to the final one in one hop.
- Tell browsers to always use https. An HSTS header makes the browser go straight to https next time, without asking the server first.
- Watch out for tracking links. Ad and email platforms often send people through their own redirect first. You can’t always remove it, but you can count it, since it’s part of TTFB for those visitors.
The connection
- Use a CDN. A CDN has servers in many cities. The visitor connects to one nearby, which makes DNS, the connection and encryption much quicker, even before anything is cached.
- Use HTTP/2 or HTTP/3, and TLS 1.3. Most hosts and CDNs turn these on for you. They set up a secure connection in fewer round trips.
- Keep DNS fast. A slow or far-away DNS provider adds time to every first visit. Big DNS providers answer from many locations.
The server’s own work
If “Waiting for server response” is the big number, the time is spent in your code. The usual causes:
- Slow or repeated database queries. One query per item in a list, a missing index or a query that loads far more than the page needs. Server-Timing usually points straight at it.
- Waiting on other services one after another. If a page calls three APIs in a row, it waits for the sum. Make independent calls at the same time.
- The server far from the database. A function in one region talking to a database in another pays the distance on every query. Put them in the same region.
- Cold starts. Serverless functions that haven’t run for a while need time to start. Smaller functions start faster, and busy pages stay warm.
- Building everything before sending anything. If the server can send the top of the page (the head, the header, the layout) while it’s still working on the rest, the first byte goes out early. Most modern frameworks can stream like this.
Caching the page
The biggest win for most sites is to stop building the same page for every visitor. A blog post, a product page or a landing page is usually the same for everyone, so it can be built once and served from a cache.
- 01Cache the HTML at the CDN. Most CDNs only cache images and scripts by default. Allow them to cache pages too with a Cache-Control header, like s-maxage=300, so the CDN serves the page from a city near the visitor.
- 02Serve stale while refreshing. stale-while-revalidate lets the CDN serve the cached page straight away and fetch a fresh one in the background. Visitors never wait for the rebuild.
- 03Build pages ahead of time. Static generation builds pages at deploy time, so there’s no server work per visit at all. If you’re on Next.js, the build output shows which routes are static and which aren’t. More in our guide to Core Web Vitals in Next.js.
- 04Keep personal bits out of the page. If one small part depends on the visitor, like a cart count or a name, load it separately in the browser. The rest of the page can then be cached for everyone.
See Core Web Vitals in Next.js for the Next.js details, and How to improve LCP for what to do once the server is fast and LCP is still slow.
Check the fix on real visits
Your own TTFB is a bad guide. You’re close to the server, your browser has the connection open, and the CDN probably has the page cached because you just loaded it. Visitors from further away, on phones, arriving from an ad, get a very different number.
TTFB is also one of the easiest numbers to break by accident. A new header that depends on the visitor can turn off caching. A new query on a popular page can double the server’s work. A change of region can put the server far from the database. None of these show up in a lab test from your desk.
That’s why CodeGecko measures TTFB from real visits next to the three Core Web Vitals, and compares each release with the one before it, page by page and on phones and desktops. It only calls a TTFB change real when it’s bigger than 5% of the old number and at least 50ms. When a deploy makes the server slower, you know the same day, with the commits that shipped, and you can split it by country to see whether distance plays a part. The docs list every metric, and the demo shows it on a sample site.
- Measure TTFB on real visits, by page and country.
- Split it into redirect, connection and server time in DevTools.
- Link to final addresses and remove redirect chains.
- Use a CDN, and let it cache pages, not only images.
- Fix slow queries and run independent calls at the same time.
- Compare each release with the one before it.
Common questions
What is a good TTFB? 0.8 seconds or less at the 75th percentile of real visits. Over 1.8 seconds is poor.
Is TTFB a Core Web Vital? No. The three Core Web Vitals are LCP, INP and CLS. TTFB is a helper metric, but a slow TTFB makes LCP slow too.
Why is my TTFB fast locally but slow for visitors? You’re close to the server and likely hitting a warm cache. Visitors further away, on slower networks or with no cache, wait for the full trip and the full server work.
Does a CDN reduce TTFB? Yes, in two ways: visitors connect to a server nearby, and if the page is cached there, the server’s work is skipped too.
Does compressing the page help TTFB? Not much. Compression makes the page smaller to download, which helps what comes after the first byte. TTFB is about how soon that first byte leaves.
NourBuilding CodeGeckoSenior frontend engineer, night-shift gamer, weekend photographer, and the human who taught a gecko to watch your deploys.

Get in early.
We’re letting teams in a few at a time. Join the waitlist and we’ll email you once, when your spot opens.
Go deeper
Keep reading

Same engine, different numbers.

How much speed counts.

Three numbers, explained.