Skip to main content
Beta: Front-End Checklist is currently in beta. Some issues are still being fixed. Thanks for your patience.

Reduce Time to First Byte (TTFB)

Measures and optimizes server response time (TTFB) to ensure a fast initial response

Utilities
Quick take
Typical fix time 10 min
  • Optimize server-side logic and database queries to speed up response generation
  • Use a Content Delivery Network (CDN) to serve content closer to users
  • Implement effective caching strategies at the server and edge levels
Why it matters: TTFB is the foundation of page performance; if the server is slow to respond, all subsequent loading stages are delayed.

Rule Details

Time to First Byte (TTFB) is the time it takes for a user's browser to receive the first byte of page content from the server. It includes the network latency and the server's processing time.

Code Examples

Setting Cache Headers

// ✅ Good: Use Cache-Control to reduce TTFB for static content
res.setHeader('Cache-Control', 'public, max-age=31536000, immutable');

Optimizing Database Queries (SQL)

-- ❌ Bad: Selecting everything
SELECT * FROM users WHERE active = true;
 
-- ✅ Good: Selecting only what's needed and using indexes
SELECT id, name, email FROM users WHERE active = true;

Using a CDN (Next.js Example)

// next.config.js
module.exports = {
  images: {
    domains: ['cdn.example.com'],
  },
}

Why It Matters

  • Foundational Metric: Everything else in the page load process waits for the first byte to arrive.
  • User Perception: A high TTFB causes users to see a blank screen or loading spinner for longer, leading to frustration.
  • SEO Impact: Search engines like Google use TTFB as part of their ranking algorithms, particularly for Core Web Vitals.
  • Server Load: Optimizing TTFB often means reducing the server's resource usage, which can save on infrastructure costs.

Best Practices

Leverage CDN Caching: Cache as much as possible at the edge to avoid hitting your origin server. ✅ Optimize Server Logic: Profile your backend code to find and fix slow functions. ✅ Efficient Database Access: Ensure your database queries are optimized and indexed correctly. ✅ Static Site Generation (SSG): For content that doesn't change often, use SSG to serve static files instantly.

Tools & Validation

Verification

Automated Checks

  • Capture a fresh request in DevTools, WebPageTest, or your APM and confirm TTFB < 800ms for key pages.
  • Inspect server logs or tracing spans for slow queries, upstream API calls, or expensive render steps before the first byte is sent.
  • Re-test from multiple geographic regions if you rely on a CDN or edge network.

Manual Checks

  • Compare cache-hit and cache-miss responses so you know whether the bottleneck is origin work or caching strategy.

Use with AI

Copy these prompts to use with your AI assistant, or install the MCP server to use directly from Claude, Cursor, or Windsurf.

Check

Verify implementation

Review the page's TTFB and identify any bottlenecks in the server-side processing or network transmission.

Fix

Auto-fix issues

Optimize the server's response time by improving database queries, caching responses, and using a CDN.

Explain

Learn more

Explain how TTFB impacts the entire page load process and why it is a critical starting point for performance optimization.

Review

Code review

Review server-rendered routes, API handlers, cache configuration, and database access on the critical path. Flag uncached HTML, slow synchronous work before the first byte, repeated upstream fetches, or expensive queries that keep TTFB above roughly 800ms.

Sources

References used to support the guidance in this rule.

Further Reading

Tools and supplementary material for exploring the topic in more depth.

PageSpeed Insights
pagespeed.web.devTool

Rules that often go hand-in-hand with this one.

Enable browser caching

Cache-Control and ETag headers are properly configured for static resources.

Performance
Enable HTTP/2 or HTTP/3

Use modern HTTP protocols to enable request multiplexing and reduce network latency.

Performance
Optimize Google Tag Manager implementation

Configure Google Tag Manager efficiently to minimize its impact on page load speed and main-thread blocking.

Performance
Avoid JavaScript-based redirects

Detects JavaScript resources that return 3XX redirects to reduce latency

Performance

Was this rule helpful?

Your feedback helps improve rule quality. This stays internal for now.

Loading feedback...
0 / 385