304 Not Modified
The HTTP 304 Not Modified
client redirection response code indicates that there is no need to retransmit the requested resources.
This response code is sent when the request is a conditional GET
or HEAD
request with an If-None-Match
or an If-Modified-Since
header and the condition evaluates to false.
It is an implicit redirection to a cached resource that would have resulted in a 200
OK
response if the condition evaluated to true.
The response must not contain a body and must include the headers that would
have been sent in an equivalent 200
OK
response:
Cache-Control
, Content-Location
,
Date
, ETag
, Expires
, and
Vary
.
Note: Many developer tools' network panels
of browsers create extraneous requests leading to 304
responses, so that
access to the local cache is visible to developers.
Status
304 Not Modified
Examples
The examples below show GET
requests made using curl with conditional request headers and the HTTP responses received in return.
The first example would return a 200
OK
if we know the resource has been updated since the timestamp in the If-Modified-Since
header.
For illustration, the request uses a future date of 21st November 2050 to check whether if the resource has been updated since this date:
curl -v --header 'If-Modified-Since: Tue, 21 Nov 2050 08:00:00 GMT' \
https://developer.mozilla.org/en-US/
> Request
GET /en-US/ HTTP/2
Host: developer.mozilla.org
User-Agent: curl/8.1.2
Accept: */*
If-Modified-Since: Tue, 21 Nov 2050 08:00:00 GMT
< Response
HTTP/2 304
date: Tue, 21 Nov 2023 08:44:28 GMT
expires: Tue, 21 Nov 2023 08:53:14 GMT
age: 3194
etag: "e27d81b845c3716cdb5d4220d78e2799"
A 304 Not Modified
response is also returned in response to a GET
request containing an If-None-Match
header with the ETag from the response above.
Because the etag
exists, a matching entity tag fails the condition, and a 304
response is returned:
curl -v --header 'If-None-Match: "e27d81b845c3716cdb5d4220d78e2799"' \
https://developer.mozilla.org/en-US/
> Request
GET /en-US/ HTTP/2
Host: developer.mozilla.org
User-Agent: curl/8.1.2
Accept: */*
If-None-Match: "e27d81b845c3716cdb5d4220d78e2799"
< Response
HTTP/2 304
date: Tue, 21 Nov 2023 08:47:37 GMT
expires: Tue, 21 Nov 2023 09:38:23 GMT
age: 2920
etag: "e27d81b845c3716cdb5d4220d78e2799"
Specifications
Specification |
---|
HTTP Semantics # status.304 |
Compatibility notes
Browser behavior differs if this response erroneously includes a body on persistent connections. See 204 No Content for more details.