Skip to content

304 Not Modified

The cached copy is still valid, so the server sends no body and the client loads the resource from its own cache.

What 304 Not Modified means

A client with a cached copy sends a conditional GET: If-None-Match with the ETag it stored, or If-Modified-Since with the Last-Modified date. If nothing has changed, the server replies 304 with no body, which saves bandwidth.

A 304 is normal HTTP caching, and seeing many of them in your network tab is a good sign. The response should repeat headers such as ETag, Cache-Control and Expires so the cache can refresh them.

Common causes

  • Visitors keep seeing an old file after a deploy because its ETag or Last-Modified value did not change.
  • A CDN or proxy answering 304 from its own stale copy.

How to fix 304 Not Modified

  1. As a visitor, do a hard refresh (Ctrl+Shift+R, or Cmd+Shift+R on a Mac) to bypass the cache.
  2. Use fingerprinted file names for static assets (app.3f9a1c.js) so every deploy gets a new URL.
  3. Make sure ETag or Last-Modified changes when the content changes, and purge the CDN cache after deploying.

Headers that go with it

  • ETag
  • If-None-Match
  • Last-Modified
  • If-Modified-Since
  • Cache-Control

Example response

HTTP/1.1 304 Not Modified
ETag: "33a64df5"

How to check for a 304 response

cURL

# Print only the status code (no -L, so the redirect isn't followed)
curl -s -o /dev/null -w "%{http_code}\n" https://example.com/

JavaScript (Node.js)

const res = await fetch("https://example.com/", { redirect: "manual" });
if (res.status === 304) {
  console.log(res.status, res.statusText, res.headers.get("location"));
}

Python

import requests

res = requests.get("https://example.com/", allow_redirects=False)
if res.status_code == 304:
    print(res.status_code, res.reason, res.headers.get("Location"))

Go

client := &http.Client{
	CheckRedirect: func(*http.Request, []*http.Request) error {
		return http.ErrUseLastResponse
	},
}
res, err := client.Get("https://example.com/")
if err != nil {
	log.Fatal(err)
}
defer res.Body.Close()
if res.StatusCode == 304 {
	fmt.Println(res.Status, res.Header.Get("Location"))
}

Specification

304 Not Modified is defined in RFC 9110, section 15.4.5.

  • 200

    OK

    The request worked. The response body holds the result, such as the page, file or JSON data the client asked for.

  • 412

    Precondition Failed

    A condition in the request headers, such as If-Match or If-Unmodified-Since, was false, so the server did not apply the request.

  • 206

    Partial Content

    The server is sending only part of the file: the byte range the client asked for in its Range header.

← all 63 HTTP status codes

Type to search posts, tools and projects.

Keyboard shortcuts

Search+Kor/
Go to homegthenh
Go to bloggthenb
Go to projectsgthenp
Go to timelinegthent
Show this help?
Close search or helpesc