Skip to content
Tutorials Center
My learning

Topics

Lesson 16 of 36 ยท Network Panel

HTTP Status Codes, Headers and Caching in DevTools

Read status codes, request and response headers, cookies and cache behavior in the Network panel, and debug 304, CORS and Cache-Control, with runnable stand-ins.

A request that "does not work" almost always shows its reason in two places: the status code and the headers. The Network panel displays both for every request, together with extra clues about whether the browser used its cache. This lesson explains how to read them and fix the common problems.

Status codes by family

The Status column shows a three-digit number. The first digit tells the family:

Family Meaning Common examples
1xx Informational 101 Switching Protocols (WebSocket upgrade)
2xx Success 200 OK, 201 Created, 204 No Content
3xx Redirect 301 Moved Permanently, 302 Found, 304 Not Modified
4xx Client error 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 429 Too Many Requests
5xx Server error 500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable

Some requests have no real status. The column then shows text such as (failed) (the network failed or a request was cancelled), (blocked:csp) or (blocked:mixed-content), or CORS error. Click the row and read the Headers tab and the Console message, which usually names the exact reason.

Rows with a red name are failed requests: a 4xx or 5xx status or a network error. Redirects (3xx) appear as separate rows, so enable Preserve log to see them before the final page replaces the list.

The Headers tab

The Headers tab has collapsible sections:

  • General: Request URL, Request Method, Status Code, Remote Address, Referrer Policy.
  • Response Headers: what the server sent: Content-Type, Content-Length, Content-Encoding, Cache-Control, ETag, Last-Modified, Set-Cookie, Access-Control-Allow-Origin, and so on.
  • Request Headers: what the browser sent: Accept, Accept-Encoding, Cookie, Authorization, Origin, User-Agent, If-None-Match.

Use the Raw toggle to see the exact text and Header Overrides (right-click a header) to edit it for testing.

Headers worth checking first when debugging:

  • Content-Type of the response: does application/json match what your code parses? A wrong type can make fetch().json() fail or an image refuse to display.
  • Content-Encoding: gzip or br means compression is on. If missing on a large text file, that is a performance opportunity.
  • Authorization or Cookie on the request: is your login or token actually being sent?
  • Location in a 3xx response: where is it redirecting you?

Network recordings contain secrets: cookies, tokens, passwords in form bodies. Never share a screenshot or HAR export publicly without removing them, and never paste real tokens into a bug report.

Caching: why a request does not go out

The browser avoids repeating work by caching responses according to headers. In the Size column you may see (memory cache) or (disk cache): the file came from the browser, no bytes crossed the network. A status of 304 Not Modified means the browser asked the server "has this changed?" and the server said "no, reuse your copy".

Two groups of headers control it:

  • Freshness: Cache-Control: max-age=3600 (fresh for an hour), Cache-Control: no-store (never store), Cache-Control: no-cache (store, but validate with the server before every use), Cache-Control: public or private, and the older Expires.
  • Validation: the server sends ETag and/or Last-Modified; on the next request the browser sends If-None-Match and/or If-Modified-Since, and the server can answer 304 without a body.

immutable tells the browser a file with that URL will never change, which pairs with file names that contain a content hash (app.4f9c1b.js) so you can cache them for a year.

To test, use Disable cache in the Network panel while DevTools is open, and without it to see real repeat-visit behavior.

Stand-in: is this response fresh?

The calculation a browser does is simple: is the age of the response less than its lifetime? This stand-in models it for max-age and shows when validation would happen. It is a simplified model; real caches also handle heuristic freshness, s-maxage, Vary and more.

JS Stand-in: cache freshness

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The "stale but has an ETag" case is exactly what you see as a 304 in the Network panel: a tiny round trip with no body, which is cheaper than a full download but not free.

CORS errors

When a page on one origin (for example https://app.example) requests data from another (https://api.example), the browser enforces CORS (cross-origin resource sharing). The server must send Access-Control-Allow-Origin naming the page's origin (or * for public data without credentials). If not, the browser blocks the response from your JavaScript and the Console shows a message that it was blocked by CORS policy.

In the Network panel you may see two rows for one call: a preflight OPTIONS request and then the real one. Preflights happen for non-simple requests (custom headers, JSON content type, methods like PUT or DELETE). The OPTIONS response must include Access-Control-Allow-Methods and Access-Control-Allow-Headers for what the real request uses.

Remember: CORS is enforced by the browser to protect users. A request that works from curl or Postman can still fail in the browser because those tools do not enforce it. The fix is on the server (or a same-origin proxy), never in the page's JavaScript.

Stand-in: a CORS checker

This stand-in decides whether a simulated response satisfies a cross-origin request, following the rules above. It teaches the logic; it is not a complete implementation (it ignores credentials and Vary).

JS Stand-in: would the browser allow this?

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Checking a response body

The Preview tab shows JSON as a tree; use it to verify the shape your code expects. The Response tab shows the raw text. A common surprise: the response is an HTML error page (for example a login redirect) when your code expects JSON. The Content-Type header and the first characters of the body make it obvious.

Also check Payload: for a POST, is the body what you meant to send (a field missing, a number sent as a string)? Use view source and view parsed toggles to compare the exact bytes with the decoded form.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does a 304 status mean?

    304 Not Modified tells the browser to reuse its cached copy after validation.
  2. 2. Which Cache-Control value stops a response from being stored at all?

    no-store forbids storing; no-cache allows storing but requires revalidation.
  3. 3. A fetch to another origin works in curl but fails in the browser with a CORS error. Where is the fix?

    CORS is a browser-enforced policy configured by the server's response headers.
  4. 4. In the Size column you see '(disk cache)'. What happened?

    (disk cache) and (memory cache) mean the response came from the local cache.

Summary

  • Status code families (2xx success, 3xx redirect, 4xx client error, 5xx server error) point to the cause; failed rows are red.
  • The Headers tab shows request and response headers; check Content-Type, Cache-Control, Authorization and Location first.
  • Freshness (max-age) and validation (ETag, 304) control caching; use Disable cache deliberately.
  • CORS is enforced by the browser and fixed on the server; look for the preflight OPTIONS row.

Next: Filtering, Throttling and Blocking Requests