TTFB Optimization: Reduce Time to First Byte
Reduce Time to First Byte (TTFB) with server-side caching, CDN configuration, and backend optimization. Practical guide for faster pages.
Auditite Team
Table of Contents
What Is Time to First Byte?
Time to First Byte (TTFB) measures the time between the browser sending a request and receiving the first byte of the response. It captures the combined latency of DNS lookup, TCP connection, TLS handshake, server processing, and network transit.
While TTFB and overall page load speed. A slow TTFB pushes everything else later — if your server takes 2 seconds to respond, your LCP cannot be faster than 2 seconds plus whatever time the LCP element needs to render.LCP and overall page load speed. A slow TTFB pushes everything else later — if your server takes 2 seconds to respond, your LCP cannot be faster than 2 seconds plus whatever time the LCP element needs to render.
Google’s recommended threshold:
- Good: TTFB under 800ms
- Target for competitive SEO: Under 200ms
What Contributes to TTFB
DNS Resolution
The browser must resolve your domain name to an IP address. This typically takes 20-100ms but can take longer with complex DNS configurations or distant DNS servers.
Optimization: Use a fast DNS provider (Cloudflare, AWS Route 53, Google Cloud DNS). Implement DNS prefetching for critical third-party domains.
TCP and TLS Handshake
Establishing a connection and negotiating encryption adds latency. TCP requires a three-way handshake, and TLS adds another round trip.
Optimization: Enable TLS 1.3 (faster handshake), use HTTP/2 or HTTP/3 (connection multiplexing), and enable 0-RTT resumption for returning visitors.
Server Processing Time
This is often the largest component of TTFB — the time your server spends generating the response. Slow database queries, unoptimized application code, and resource contention all extend processing time.
Network Transit
The physical distance between your server and the user affects transit time. A server in Frankfurt serving a user in Sydney adds roughly 300ms of round-trip latency.
Optimization: Use a CDN to serve content from edge locations worldwide.
Server-Side Optimization Strategies
Implement Full-Page Caching
For pages that do not change with every request (blog posts, product pages, landing pages), cache the complete HTML response:
- Reverse proxy caching with Nginx, Varnish, or Cloudflare
- Application-level caching storing rendered HTML in Redis or Memcached
- Static site generation for content that changes infrequently
Full-page caching can reduce TTFB from seconds to single-digit milliseconds.
Optimize Database Queries
Slow database queries are the most common cause of high TTFB on dynamic sites:
- Add indexes on columns used in WHERE, JOIN, and ORDER BY clauses
- Avoid N+1 queries — use eager loading for related data
- Cache query results for frequently accessed, rarely changing data
- Use query analysis tools to identify slow queries
- Implement connection pooling to reduce connection overhead
Reduce Application Overhead
Review your application code for:
- Unnecessary middleware that runs on every request
- Synchronous external API calls that block response generation
- Heavy template rendering that can be simplified or cached
- Logging overhead — reduce verbose logging in production
Use Efficient Hosting
Your hosting infrastructure directly determines your TTFB floor:
- Dedicated servers or cloud instances outperform shared hosting
- SSD storage dramatically reduces database read times
- Adequate RAM prevents disk swapping during traffic spikes
- Auto-scaling handles traffic spikes without degradation
CDN Configuration for TTFB
A CDN is the single most impactful TTFB optimization for global audiences. Key configuration considerations:
Edge Caching Rules
Configure your CDN to cache HTML responses at the edge for appropriate page types. Set cache TTLs based on content freshness requirements:
- Static marketing pages — Cache for hours or days
- Blog posts — Cache for 1-4 hours with purge on update
- Dynamic pages — Use stale-while-revalidate to serve cached content while fetching fresh data in the background
Cache Key Optimization
Ensure your CDN cache keys do not include unnecessary variations. Common mistakes:
- Including all query parameters in the cache key (breaks caching for UTM-tagged URLs)
- Varying by user agent when the content is the same for all browsers
- Including cookies in the cache key for pages that do not use cookies
Edge Computing
Modern CDNs (Cloudflare Workers, AWS Lambda@Edge, Vercel Edge Functions) can execute application logic at the edge, combining the speed of CDN delivery with the flexibility of server-side rendering.
For a deeper dive into CDN strategy, read our CDN strategies for SEO performance guide.
Measuring TTFB
Server-Side Monitoring
Monitor TTFB from your server’s perspective using application performance monitoring (APM) tools. This reveals server processing time separately from network latency.
Real User Monitoring
Use the Navigation Timing API or performance monitoring services to measure TTFB from real users:
const ttfb = performance.getEntriesByType('navigation')[0].responseStart;
Synthetic Monitoring
Test TTFB from multiple global locations regularly to identify geographic performance gaps and CDN configuration issues.
Google’s Tools
- PageSpeed Insights — Shows TTFB in the diagnostics section
- Chrome User Experience Report — Real-user TTFB data by origin
- Lighthouse — Flags high TTFB as a performance issue
TTFB Optimization by Platform
WordPress
- Install a caching plugin (WP Super Cache, W3 Total Cache, or WP Rocket)
- Use object caching with Redis or Memcached
- Optimize the database regularly (remove transients, post revisions)
- Use a CDN for both static assets and HTML
Node.js / Express
- Implement response caching with Redis
- Use cluster mode to leverage multiple CPU cores
- Optimize middleware stack — remove unnecessary middleware
- Enable gzip/brotli compression at the application or CDN level
Static Sites (Astro, Hugo, Next.js Static)
Static sites naturally have excellent TTFB because pages are pre-built HTML files. Deploy to a CDN for global edge delivery and sub-50ms TTFB worldwide.
TTFB and Crawl Budget
Server response time directly affects your crawl budget. When Googlebot encounters slow response times, it reduces its crawl rate to avoid overloading your server. This means fewer pages crawled per day and slower indexation of new or updated content.
A consistently fast TTFB signals to Googlebot that your server can handle more requests, potentially increasing your crawl allocation.
Key Takeaways
TTFB is the foundation that every other performance metric builds on:
- Implement full-page caching for static and semi-static content
- Optimize database queries — the most common bottleneck
- Use a CDN to reduce network latency for global audiences
- Monitor continuously from multiple locations and with real users
- Target under 200ms for competitive SEO advantage
Fast TTFB improves LCP, increases crawl rates, and provides a better experience for every visitor to your site.
Stay in the loop
Get insights, strategies, and product updates delivered to your inbox.
No spam. Unsubscribe anytime.
Ready to see Auditite in action?
Get started and see how Auditite can transform your SEO auditing workflow.
Get started