304 Not Modified
When a conditional request confirms the resource has not changed since the client's last cached copy, the server responds with 304 Not Modified. The response carries no message body and instructs the client to reuse its stored representation.
Usage
The 304 Not Modified status code is sent in response to a conditional GET or HEAD request when the server determines the resource has not changed since the version stored in the client's cache. This conserves bandwidth because the server does not retransmit data the client already holds. The code is reserved for those two methods. A PUT, POST or DELETE whose If-None-Match precondition fails receives 412 instead.
The server generates one or more of the following headers in response:
Because the goal of the 304 Not Modified response is to minimize bandwidth, the server sends these headers with the values a full 200 response would have carried, and omits other representation metadata unless the information aids the cache-update process.
For conditional GET requests, the relevant headers are If-None-Match, which carries the ETag the client holds, and If-Modified-Since, which carries the Last-Modified date. The server compares each against the current validator of the resource to decide whether the resource needs retransmission. A 304 is only possible when an earlier response carried one of those validators: a resource served without ETag and Last-Modified gives the client nothing to revalidate with.
Example
The client requests a resource, receives an ETag identifying the version, then later revalidates. The server recognizes the resource is unchanged and returns 304 Not Modified. On the third request, a new version is available and a full 200 response is sent with an updated ETag.
Initial request
GET /news.html HTTP/1.1
Host: www.example.re
Initial response
HTTP/1.1 200 OK
ETag: "1234000"
Content-Type: text/html
Content-Length: 1250
<1250 bytes of HTML>
Second request
GET /news.html HTTP/1.1
Host: www.example.re
If-None-Match: "1234000"
Second response
HTTP/1.1 304 Not Modified
ETag: "1234000"
Third request
GET /news.html HTTP/1.1
Host: www.example.re
If-None-Match: "1234000"
Third response
HTTP/1.1 200 OK
ETag: "1234001"
Content-Type: text/html
Content-Length: 1600
<1600 bytes of HTML>
Crawlers and 304
Search crawlers revalidate with both validators, so a page served with ETag and Last-Modified earns a 304 from every crawler that supports caching. Google documents support for If-None-Match and If-Modified-Since, uses the ETag when both validators are present, and recommends ETag because it avoids date formatting mistakes. Googlebot's smartphone crawler sends If-Modified-Since on recrawls, Bingbot and Baiduspider revalidate with If-None-Match, and SeznamBot sends If-Modified-Since. Sending both headers covers all of them.
The stale 304 trap
A 304 confirms the cached version is still current, and the server decides that by comparing validators, not by inspecting content. When the validator is not tied to the content, the server keeps answering 304 after the page has changed. Typical causes are an ETag computed from a template or deployment identifier rather than from the rendered body, a Last-Modified date copied from a file the page no longer depends on, or a CDN that keeps serving an old validator from its own cache after the origin changed.
The symptom is a page that was fixed, an error body or empty template replaced with real content, while crawlers and browsers that hold the broken copy keep receiving 304 and never see the fix. The remedy is a validator that changes whenever the body changes: a strong ETag derived from the content, or a Last-Modified date updated on every publish. Checking the fix is a single conditional request with the old validator, which must come back as a 200 with the new body.
Code references
.NET
HttpStatusCode.NotModified
Rust
http::StatusCode::NOT_MODIFIED
Rails
:not_modified
Go
http.StatusNotModified
Symfony
Response::HTTP_NOT_MODIFIED
Python3.5+
http.HTTPStatus.NOT_MODIFIED
Java
java.net.HttpURLConnection.HTTP_NOT_MODIFIED
Apache HttpComponents Core
org.apache.hc.core5.http.HttpStatus.SC_NOT_MODIFIED
Angular
@angular/common/http/HttpStatusCode.NotModified
See also
- RFC 9110: HTTP Semantics
- Google: HTTP status codes and network errors
- Google: Overview of Google crawlers and fetchers (HTTP caching)
- 200
- 412
- If-Modified-Since
- If-None-Match
- ETag
- Last-Modified
- Conditional-Requests
- Caching
- HTTP status codes