User Agents

Web browsers and everyday web tech, explained

Fetch 404 Head Request Chrome Explained

· 6 min read · Browsers

In this article
  1. Background: HTTP Methods and Browser Behavior
  2. How Fetch Handles HTTP Status Codes
  3. Chrome’s Network Stack and Fetch Implementation
  4. Why This Matters for Developers
  5. Common Problems and Misunderstandings
  6. Alternatives to Fetch for HEAD Requests
  7. Frequently Asked Questions

Fetch can resolve a 404 HEAD request in Chrome because the browser's network stack and the fetch API handle HTTP methods and responses differently than traditional navigation or script-based XHR calls, allowing successful processing of status codes like 404 without halting execution. Unlike page navigation, which treats a 404 as a failure requiring user intervention, fetch treats the response as valid network communication—even if the requested resource is not found—enabling developers to programmatically inspect headers and status codes for debugging, routing, or conditional logic.

Background: HTTP Methods and Browser Behavior

HTTP defines several request methods, including GET, POST, PUT, DELETE, and HEAD. The HEAD method is identical to GET but instructs the server to return only the response headers, not the body. This is useful for checking metadata such as content length, last modified date, or cache headers without transferring the full resource. Browsers use HEAD requests internally for optimization, such as pre-checking resource availability before loading assets.

When a user navigates to a URL in the address bar and the server returns a 404, Chrome displays an error page. However, when a script initiates a HEAD request via the fetch API, the browser treats the 404 not as a fatal error but as a legitimate HTTP response. This distinction is crucial: fetch resolves when the network exchange completes successfully, regardless of the HTTP status code. A 404 means "not found," not "communication failed."

How Fetch Handles HTTP Status Codes

The fetch API in modern browsers, including Chrome, operates on a two-tier success model:

  • Network success: The request reached the server and a response was received, even if it's a 4xx or 5xx status.
  • Application-level success: Determined by the developer, often based on whether the status is in the 2xx range.

This means that fetch promises resolve as long as there's a response from the server. A 404 response includes headers and a status line, so fetch considers the request completed. Developers must explicitly check response.ok or response.status to determine if the outcome was logically successful.

Example:

fetch('/missing-page', { method: 'HEAD' })
  .then(response => {
    console.log(response.status); // Logs 404
    console.log(response.ok);     // Logs false
    // Response headers are still accessible
    console.log(response.headers.get('content-type'));
  });

This behavior enables scripts to react intelligently to missing resources—perhaps falling back to a default or logging the error—without crashing.

Chrome’s Network Stack and Fetch Implementation

Chrome uses the Blink rendering engine and the Chromium network stack, which powers the fetch API. This stack handles all HTTP communication, including redirects, compression, caching, and CORS. When a fetch call is made, Chrome routes it through this unified system, which treats all HTTP responses as data, not user-facing errors.

Unlike XMLHttpRequest (XHR), fetch is promise-based and designed for modern asynchronous workflows. It does not throw a JavaScript error for HTTP 4xx or 5xx responses. Instead, it delivers the response object, giving developers full access to headers, status, and (in the case of GET) body—even on a 404. This is especially valuable for HEAD requests, where the body is empty by definition, but headers may still contain diagnostic information.

For example, a HEAD request to a deleted API endpoint might return a 404 with a Retry-After header, indicating when the resource might be available again. Fetch allows scripts to read that header and schedule a retry.

Why This Matters for Developers

Understanding that fetch resolves on network-level success is critical for robust web applications. It allows developers to:

  • Check resource availability before attempting to load them
  • Implement fallback mechanisms for missing assets
  • Monitor API health by probing endpoints
  • Handle authentication redirects or rate-limiting headers even on error responses

A common misconception is that a 404 should reject the fetch promise. But HTTP status codes are part of the application layer, not the transport. If the TCP connection succeeds and the server responds with a well-formed HTTP message, the fetch is considered complete.

For instance, a single-page application (SPA) might use a HEAD request to verify if a user-specific configuration file exists before rendering:

async function loadUserConfig(userId) {
  const response = await fetch(`/api/config/${userId}`, { method: 'HEAD' });
  
  if (response.ok) {
    // Proceed to GET the full config
    const config = await fetch(`/api/config/${userId}`).then(r => r.json());
    return config;
  } else if (response.status === 404) {
    // Use default config
    return getDefaultConfig();
  } else {
    throw new Error(`Unexpected status: ${response.status}`);
  }
}

Common Problems and Misunderstandings

Developers often expect fetch to reject on 404, leading to bugs when error handling is omitted. Here are typical issues:

  • Assuming response.ok: Forgetting to check response.ok can lead to parsing errors when trying to read a body from a 404.
  • Confusing network errors with HTTP errors: A network failure (e.g., DNS error, offline) rejects the fetch promise. A 404 resolves it. These must be handled differently.
  • HEAD requests returning 404 with useful headers: Some servers include Link, X-Deprecated, or Location headers even on 404s. Ignoring these wastes diagnostic data.

Another issue is CORS: if a HEAD request is made to a different origin and the server doesn’t include proper CORS headers, the browser blocks access to the response, even if the network request succeeded. This results in a different kind of error—CORS failure—not a 404.

Alternatives to Fetch for HEAD Requests

While fetch is the modern standard, other methods exist:

  • XMLHttpRequest (XHR): Older but still functional. Like fetch, it delivers 404 responses without throwing, but requires more boilerplate.
  • Beacon API: For sending data without waiting for a response; not suitable for HEAD requests.
  • Image or Link preload: Browsers use HEAD internally when preloading resources, but scripts can’t access the response.
  • Service Workers: Can intercept and simulate HEAD responses, useful for offline handling.

None of these alternatives provide the same combination of simplicity, promise-based flow, and header access as fetch.

Frequently Asked Questions

Does a 404 response reject the fetch promise?

No. The fetch promise resolves as long as the server responds, even with a 404. Only network-level failures—like no internet or DNS errors—cause rejection.

Can I read headers from a 404 HEAD response?

Yes. As long as the server sends headers and CORS permits access, you can read them via response.headers.get('header-name'), even with a 404 status.

Why does Chrome allow 404s to resolve in fetch?

Because HTTP 404 is a valid server response, not a network failure. Chrome treats all HTTP responses as data, letting developers decide how to interpret them.

Is this behavior the same in other browsers?

Yes. All modern browsers implement fetch according to the Fetch Standard, so 404 responses resolve the promise consistently across Chrome, Firefox, Safari, and Edge.

Can a HEAD request return a body?

No. By HTTP specification, HEAD requests must not include a response body. The server sends only headers, even if the equivalent GET would include a body.

What happens if the server doesn’t support HEAD?

If the server returns a 405 Method Not Allowed, fetch still resolves. You can check response.status to detect this and fall back to a GET with no body or another method.