Troubleshooting guide
How to reduce TTFB (server response time)
Time to first byte is the foundation of every page load. These fixes are ordered by how much they usually help, starting with the ones that remove work entirely.
3 min read10 sectionsUpdated
On this page
Measure first
Split TTFB into its parts and see which one dominates. Use real-user data for the field picture by country, and a trace for the server part:
for i in 1 2 3; do
curl -o /dev/null -s -w 'dns=%{time_namelookup} tcp=%{time_connect} tls=%{time_appconnect} ttfb=%{time_starttransfer}\n' https://example.com/
done| Fix | Helps when | Typical gain |
|---|---|---|
| Cache full HTML at a CDN | Pages are the same for all visitors | Server time drops to near zero for cache hits |
| Remove redirects | Links go via http:// or a non-canonical host | One round trip per removed hop |
| Fix slow queries and N+1 patterns | Traces show long database spans | Often hundreds of milliseconds |
| Cache expensive fragments | Some data is slow but changes rarely | Large, on every request |
| Serve from closer regions | Visitors are far from the origin | Round-trip time per hop |
| Avoid cold starts | Serverless or scale-to-zero | Removes occasional multi-second waits |
| HTTP/2 or HTTP/3, TLS 1.3 | Older stacks | Fewer round trips for connection setup |
Caching HTML safely
Personalized pages cannot be shared, but most of a marketing site, documentation or blog can. Common patterns:
- Cache-Control with s-maxage for the CDN and a short max-age for browsers.
- stale-while-revalidate so visitors get a cached page while a fresh one is fetched in the background.
- Vary or bypass rules for signed-in users and carts.
- Purge on publish, so content edits appear immediately.
Cache-Control: public, max-age=60, s-maxage=600, stale-while-revalidate=86400Making the server part faster
Open a trace for a slow request. Typical findings: one query that needs an index, the same query run once per item (N+1), a call to an external API on every page view, or template rendering that loads far more data than it shows. Fix the biggest span first and re-measure. See how to find slow database queries and our guide to caching for content sites.
Keep it from creeping back
Track TTFB at the 75th percentile per page from real users, and server latency per route in APM. VitalRix real user monitoring and APM show both, so a regression after a release is visible the same day.
What is a good TTFB?
0.8 seconds or less at the 75th percentile of real page views is considered good. Cached pages served from a nearby CDN are often well under 200 ms.
Does a CDN always reduce TTFB?
Only for content it can serve from cache. For uncached, dynamic pages the CDN adds a hop, though connection reuse to your origin often still helps a little.
Check it now, free
- Response time checker: Measure TTFB with DNS, connect, TLS and server time.
Related reading
- How to reduce First Contentful Paint (FCP): Reduce First Contentful Paint: lower TTFB, remove render-blocking CSS and scripts, load fonts sensibly and measure improvements with real-user data.
- How to improve LCP (Largest Contentful Paint): Improve Largest Contentful Paint by fixing the slowest of its four parts: server time, discovery delay, download time and render delay, with code.
- IRCTC slow or not working at Tatkal time: what to do: Why IRCTC slows down at 10 and 11 a.m. Tatkal opening, how to check if it is down, and practical steps to book faster with fewer errors and payment failures.
- What is Total Blocking Time (TBT)?: Total Blocking Time explained: long tasks, how TBT is calculated, the 200 ms target in Lighthouse, how it relates to INP and how to break up main-thread work.
- How to fix CLS (Cumulative Layout Shift): Fix Cumulative Layout Shift: reserve space for images, ads and embeds, tame web fonts, avoid injected banners and animate safely, with code to copy.
- What is log optimization?: Log optimization explained: finding the noisiest log sources, levels and sampling, structured fields, dropping duplicates, retention tiers.
Watch your own site and services with VitalRix
Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.