Skip to main content
HTTP & Networking

HTTP Headers Every Developer Should Check First

A staging server returns 200, the page renders, and nobody looks at headers until something breaks — a stale file, a redirect loop, a login that logs users out after five minutes. Almost every one of those bugs is visible in the response headers, for free, before any code change. Here is the short list worth checking first, and the mistakes that go with each.

Cache-Control is a contract, not a suggestion

The most expensive header mistake in web development is shipping HTML with no Cache-Control at all. Browsers then use heuristic caching: a response without explicit directives can be cached based on Last-Modified, which is why users see yesterday's version of your app and a hard refresh becomes a support ticket.

Rules that hold in practice:

  • HTML and API responses: no-cache (or max-age=0, must-revalidate). Always revalidate — correctness beats a saved round trip.
  • Hashed static assets (app.8f3a2c.js): public, max-age=31536000, immutable. The filename changes with content, so a year is safe.
  • Never put credentials, tokens, or personalized payloads under public caching — including s-maxage on a shared CDN cache. That is how one user's account page leaks to another.

A real failure mode: an SPA deployed where index.html inherited max-age=31536000 from a catch-all static rule. The next release shipped a renamed JS bundle; two days later users still loaded the old HTML pointing at a 404 asset. The fix was one line of nginx config, found in under a minute by reading response headers.

Content-Type: when charset bites

application/json without charset=utf-8 still bites legacy consumers, and text endpoints without an explicit charset let browsers guess — historically windows-1252. The canonical case: a CMS stored em dashes as UTF-8 and rendered them as mojibake in production, because the server sent text/html without a charset while the meta tag loaded too late to matter.

Also worth knowing: JSON is defined as UTF-8, so charset=utf-8 there is redundant-but-harmless; but text/csv downloads opened in Excel go full mojibake without an explicit charset plus a UTF-8 BOM. If your API is strict, reject requests whose Content-Type does not match the contract — a clean 415 beats a corrupted import.

Security headers that are cheap to set

  • Strict-Transport-Security: max-age=31536000; includeSubDomains once HTTPS is truly site-wide. Check every subdomain first — HSTS is remembered for a year, even after you break HTTPS.
  • X-Content-Type-Options: nosniff: stops browsers from reinterpreting a user-uploaded file as script. One line, no downside.
  • Content-Security-Policy: start in Report-Only mode, collect violation reports, then enforce. Shipping a strict CSP blind on a legacy app breaks inline handlers and third-party tags in ways QA will not catch.
  • X-Frame-Options: DENY (or CSP frame-ancestors): the only real fix for clickjacking on admin pages.

The failure pattern is always the same: headers set on HTML but not on API responses, or set on the app but stripped by the CDN layer in front of it. Set them at the edge that actually serves the traffic.

CORS: one origin at a time

Access-Control-Allow-Origin: * works only for anonymous, public read endpoints. The moment you send credentials — cookies via Access-Control-Allow-Credentials: true or an Authorization header — the wildcard is forbidden by the spec and the browser rejects the response. Practical rules:

  • Mirror the Origin header only if it is on your allowlist; never echo arbitrary origins back.
  • Every header you add to the request needs an entry in Access-Control-Allow-Headers, or the preflight (OPTIONS) fails and the real request never fires. This is the classic "works in Postman, fails in the browser" bug.
  • CORS is enforced by the browser, not the server. curl bypasses it entirely, so "it works in curl" proves nothing about browser behavior.

Location, Retry-After, and the status/header pairs

A 301 with no Location header is a broken redirect; a 301 pointing at another 301 burns a round trip per hop, and crawlers stop following after a handful of hops. Redirect chains are also a direct SEO leak. Retry-After on 429 and 503 is what lets a well-behaved client back off instead of hammering you — if you build rate limiting, send it.

And the pair that saves post-mortems: an X-Request-Id header echoed in the response. When a user pastes one ID into a support ticket and it matches a log line, diagnosis goes from minutes to seconds. Generate the ID at the edge and propagate it through every hop.

Checking headers without opening devtools

Headers are also the fastest way to audit an environment: compare staging against production and look for the deltas — a missing CSP, a different cache policy, or a server header advertising a version you would rather not publish.

The HTTP Headers Inspector on ToolFYou shows the full request and response header set for any URL, which is the quickest way to compare two environments side by side. For cache rules specifically, the HTTP Availability Checker confirms a URL responds the way you expect after a deploy — useful when a CDN keeps serving stale content while origin is already fixed. And if a header change involves a new domain or a moved DNS record, the DNS Propagation Checker tells you whether you are debugging headers or just waiting for resolvers to catch up.

The one-pass checklist

After each deploy, read six lines: Cache-Control (HTML must revalidate), Content-Type (charset present), Strict-Transport-Security (present, sane max-age), X-Content-Type-Options: nosniff, CORS allowlist on authed endpoints (no wildcard), and Location paired with each redirect status. Everything else can wait for a security review; these six decide whether your users see the right bytes at all.