How-To Guide

Diagnosing Slow API Bottlenecks from HAR Traces

Read HAR 1.2 waterfall timings across DNS, TLS, TTFB, and Blocked queues, strip sensitive auth headers safely, and isolate slow backend calls.

On this page

  1. Why Screenshots Miss Root Causes in Slow Web Apps
  2. Decoding HAR 1.2 Timing Phases Accurately
  3. Sanitizing Secrets and Summarizing Slow Outliers
  4. Detecting Sequential Waterfalls and Connection Contention
  5. Common HAR Analysis Pitfalls and Misreads
  6. Verifying Fixes via Before/After Trace Comparisons

Why Screenshots Miss Root Causes in Slow Web Apps

When a teammate reports “the dashboard takes four seconds to load”, pasting a screenshot of three red network rows tells almost nothing about where time vanished. Did the browser spend 1.8 seconds waiting on HTTP/1.1 connection slots (blocked), burn 600ms negotiating fresh TCP + TLS connections (connect and ssl), stall inside backend database queries (wait), stream a 4MB uncompressed JSON payload (receive), or execute five sequential useEffect waterfalls back-to-back?

The W3C HTTP Archive (HAR 1.2) JSON specification captures exact microsecond timestamps, byte sizes, MIME types, and status codes for every HTTP request inside a browser session. Inspecting HAR entries programmatically—and redacting secrets immediately—lets engineers separate network physics from backend CPU bottlenecks in minutes. You can inspect HAR 1.2 request waterfalls, MIME distributions, status breakdowns, and slowest outliers locally in your browser via the Interactive HAR Waterfall Analyzer.

Decoding HAR 1.2 Timing Phases Accurately

Every request inside log.entries[] contains startedDateTime, total time, request, response, and a timings object broken into seven mutually exclusive phases (where -1 indicates the phase did not apply, such as DNS/TLS on a reused keep-alive socket):

  • blocked (Stalled): Time spent sitting in the browser’s queue waiting for an open socket slot (classic HTTP/1.1 6-socket limit per hostname), proxy negotiation, or cache lock checks.
  • dns: Hostname resolution time (-1 when served from OS/browser DNS cache or pooled connection).
  • connect: TCP three-way handshake duration (note: in HAR 1.2, connect includes ssl time per specification—subtract ssl when computing raw TCP SYN-ACK time!).
  • ssl: TLS handshake negotiation (-1 for plaintext HTTP or resumed sockets).
  • send: Time spent writing request headers and body onto the socket.
  • wait (TTFB): Time To First Byte—how long the client waited after finishing send until the very first byte of the server response arrived. High wait points straight at backend latency, database locks, or missing CDN caching.
  • receive: Time spent reading response body bytes from the network until completion.

Sanitizing Secrets and Summarizing Slow Outliers

Never upload raw .har dumps straight from Chrome DevTools into bug trackers without redacting Authorization, Cookie, Set-Cookie, and custom API key headers first. The TypeScript helper below scrubs sensitive headers/cookies in-memory while simultaneously ranking the worst TTFB outliers, oversized payloads, and total waterfall critical path.

export interface HarEntry {
  startedDateTime: string;
  time: number;
  request: {
    method: string;
    url: string;
    headers: Array<{ name: string; value: string }>;
    cookies?: Array<{ name: string; value: string }>;
  };
  response: {
    status: number;
    headers: Array<{ name: string; value: string }>;
    content: { size: number; mimeType: string };
    _transferSize?: number;
  };
  timings: {
    blocked?: number;
    dns?: number;
    connect?: number;
    ssl?: number;
    send: number;
    wait: number;
    receive: number;
  };
}

const SENSITIVE_HEADERS = new Set([
  "authorization",
  "proxy-authorization",
  "cookie",
  "set-cookie",
  "x-api-key",
  "x-csrf-token",
]);

export function sanitizeHarEntries(entries: HarEntry[]): HarEntry[] {
  return entries.map((entry) => ({
    ...entry,
    request: {
      ...entry.request,
      headers: entry.request.headers.map((h) =>
        SENSITIVE_HEADERS.has(h.name.toLowerCase())
          ? { name: h.name, value: "[REDACTED]" }
          : h,
      ),
      cookies: entry.request.cookies?.map((c) => ({ name: c.name, value: "[REDACTED]" })),
    },
    response: {
      ...entry.response,
      headers: entry.response.headers.map((h) =>
        SENSITIVE_HEADERS.has(h.name.toLowerCase())
          ? { name: h.name, value: "[REDACTED]" }
          : h,
      ),
    },
  }));
}

export function summarizeHarBottlenecks(entries: HarEntry[]) {
  if (entries.length === 0) {
    return { totalRequests: 0, wallClockMs: 0, topWaitMs: [] };
  }

  let minStart = Infinity;
  let maxEnd = -Infinity;

  const ranked = entries.map((e) => {
    const startMs = Date.parse(e.startedDateTime);
    const endMs = startMs + e.time;
    if (startMs < minStart) minStart = startMs;
    if (endMs > maxEnd) maxEnd = endMs;

    const tcpOnlyMs =
      e.timings.connect && e.timings.connect > 0
        ? Math.max(0, e.timings.connect - Math.max(0, e.timings.ssl ?? 0))
        : 0;

    return {
      method: e.request.method,
      path: new URL(e.request.url).pathname,
      status: e.response.status,
      totalMs: Math.round(e.time),
      blockedMs: Math.max(0, Math.round(e.timings.blocked ?? 0)),
      tcpMs: Math.round(tcpOnlyMs),
      tlsMs: Math.max(0, Math.round(e.timings.ssl ?? 0)),
      ttfbMs: Math.round(e.timings.wait),
      receiveMs: Math.round(e.timings.receive),
      transferBytes: e.response._transferSize ?? e.response.content.size ?? 0,
    };
  });

  ranked.sort((a, b) => b.ttfbMs - a.ttfbMs);

  return {
    totalRequests: entries.length,
    wallClockMs: Math.round(maxEnd - minStart),
    topWaitMs: ranked.slice(0, 5),
  };
}

Notice how summarizeHarBottlenecks computes tcpOnlyMs by subtracting ssl from connect, preventing engineers from double-counting TLS negotiation time inside TCP handshake latency! Also notice response._transferSize versus response.content.size: content.size shows uncompressed decoded body bytes, whereas _transferSize (when present) captures actual wire bytes after Brotli/gzip compression. Comparing those two reveals instantly whether your API forgot Content-Encoding: br or gzip.

Detecting Sequential Waterfalls and Connection Contention

One of the highest-leverage patterns revealed by HAR analysis is request serialization—often invisible in backend APM traces because each individual endpoint reports a fast 120ms execution time! When React mounts a parent shell, waits for /api/session (150ms), then triggers /api/org (150ms), and only then mounts a child widget calling /api/projects (150ms) and /api/billing (150ms), the user waits 600ms of stacked TTFB plus serial render delays.

To detect cascades automatically in CI or performance triage, sort entries by startedDateTime and flag any API fetch whose start timestamp lands right within ±15ms of a preceding API response’s completion (prevStart + prevTime). Replacing serialized client waterfalls with Promise.all(...), route loaders, or HTTP/2 server-side aggregation immediately cuts page-interactive latency without changing a single SQL query.

# Quick CLI inspection and secret scrubbing check via jq before sharing traces
jq '.log.entries | map({
  method: .request.method,
  url: (.request.url | split("?")[0]),
  status: .response.status,
  waitMs: (.timings.wait | round),
  sizeKb: ((.response._transferSize // .response.content.size) / 1024 | round)
}) | sort_by(-.waitMs) | .[0:10]' capture.clean.har

Common HAR Analysis Pitfalls and Misreads

Avoid four traps that regularly derail performance postmortems:

  • Recording with browser cache warm or DevTools throttling forgotten: Capturing a HAR with warm service workers masks CDN miss costs, whereas accidentally leaving DevTools set to “Slow 3G” creates phantom 1,200ms TLS and receive bars that waste backend engineers’ time. Always record clean profiles and inspect log.pages and _transferSize.
  • Ignoring CORS preflight OPTIONS overhead in waterfalls: Every cross-origin write or custom-header GET without Access-Control-Max-Age triggers a full sequential OPTIONS round trip ahead of the real fetch, doubling apparent endpoint TTFB on high-latency mobile links.
  • Confusing HTTP/1.1 connection queueing with server slowness: If entries 7 through 14 show blocked: 480ms and wait: 35ms, your backend is fast—your domain is still serving assets over HTTP/1.1 or sharded across hostnames without HTTP/2 multiplexing.
  • Sharing un-redacted .har files containing postData: Even after scrubbing Authorization headers, request.postData.text inside login or webhook forms still retains plaintext user passwords or PII! Drop or mask postData fields whenever exporting traces outside secure vaults.

Verifying Fixes via Before/After Trace Comparisons

Once you compress oversized JSON payloads, parallelize chained fetch calls, or enable HTTP/2 keep-alive, capture a fresh .har trace under identical conditions and compare both snapshots in the Interactive HAR Waterfall Analyzer. Verify four measurable improvements:

  1. Total wallClockMs across the critical user journey shrinks proportionally as sequential chains collapse into concurrent batches.
  2. blocked duration across API bursts stays near zero (< 10ms) rather than queuing behind 6-socket ceilings.
  3. Large JSON responses show _transferSize compressed to 15–30% of content.size via Brotli/gzip.
  4. Any sanitized trace committed to issue trackers passes a secret-scanner check verifying [REDACTED] covers all cookies, tokens, and postData credentials, and zero unmasked query parameters (?token= or ?code=) survive inside logged URLs. Finally, archive baseline HAR snapshots alongside release tags so engineers can spot regression waterfalls immediately during future performance reviews.

FAQ

Why is exporting a raw HAR file dangerous to share in GitHub issues or Slack?
A HAR 1.2 JSON file records every request and response header verbatim—including active session cookies, OAuth Bearer tokens, CSRF nonces, and private JSON response payloads. Always sanitize sensitive headers before sharing.
What does high 'blocked' or 'stalled' time mean in a HAR waterfall?
High blocked time means the browser could not put the request on the wire yet—commonly caused by HTTP/1.1's 6-connection-per-origin limit, slow main-thread JavaScript blocking fetch dispatch, or disk cache lock contention.
How do I tell backend processing delay apart from slow mobile network download?
Check timings.wait (TTFB) versus timings.receive. Long wait indicates upstream server computation, cold starts, or database queries; long receive with tiny wait means an un-compressed or multi-megabyte payload saturating client bandwidth.

Related Examples

Interactive Tools for This Topic