What Is a 304 Status Code?
A conditional GET or HEAD request has been received and would have resulted in a 200 OK response if it were not for the fact that the condition evaluated to false.
In other words, there is no need for the server to transfer a representation of the target resource because the request indicates that the client, which made the request conditional, already has a valid representation; the server is therefore redirecting the client to make use of that stored representation as if it were the payload of a 200 OK response.
The server generating a 304 response MUST generate any of the following header fields that would have been sent in a 200 OK response to the same request: Cache-Control, Content-Location, Date, ETag, Expires, and Vary.
Since the goal of a 304 response is to minimize information transfer when the recipient already has one or more cached representations, a sender SHOULD NOT generate representation metadata other than the above listed fields unless said metadata exists for the purpose of guiding cache updates (e.g., Last-Modified might be useful if the response does not have an ETag field).
Requirements on a cache that receives a 304 response are defined in Section 4.3.4 of RFC7234. If the conditional request originated with an outbound client, such as a user agent with its own cache sending a conditional GET to a shared proxy, then the proxy SHOULD forward the 304 response to that client.
A 304 response cannot contain a message-body; it is always terminated by the first empty line after the header fields.
- Source: RFC7232 Section 4.1
304 CODE REFERENCES
Rails HTTP Status Symbol :not_modified
Go HTTP Status Constant http.StatusNotModified
Symfony HTTP Status Constant Response::HTTP_NOT_MODIFIED
Python2 HTTP Status Constant httplib.NOT_MODIFIED
Python3+ HTTP Status Constant http.client.NOT_MODIFIED
Python3.5+ HTTP Status Constant http.HTTPStatus.NOT_MODIFIED
.NET HttpStatusCode.NotModified
Rust http::StatusCode::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
304 status code example
Here’s an example of a request and response for a 304 status code:
Request
GET /article HTTP/1.1
Host: example.com
If-Modified-Since: Thu, 25 Feb 2021 10:30:00 GMT
In this example, the client is requesting an article from the server with a GET request. The client is also sending an If-Modified-Since header, indicating that it has a cached version of the article that it received on or after the specified date and time.
Response
HTTP/1.1 304 Not Modified
Date: Thu, 25 Feb 2021 10:35:00 GMT
In this example, the server is responding with a 304 Not Modified status code, indicating that the requested resource has not been modified since the client’s cached version of the resource. The server is not sending a new version of the resource in the response, but instead instructs the client to use the cached version that it already has.
How to fix a 304 status code
A 304 status code is not an error code but rather an indication to the client that it can use its cached copy of the requested resource. Therefore, there is no “fix” for a 304 status code, as it is not indicating an error that needs to be resolved.
However, if a client is consistently receiving 304 status codes for a particular resource, it may indicate that the client’s caching settings need to be adjusted. For example, the client’s cache may be set to expire too frequently, causing it to repeatedly request the same resource from the server. Adjusting the cache expiration settings can help reduce the number of requests and improve performance.
If the server is not returning a 304 status code when the requested resource has not been modified, it may indicate an issue with the server’s caching settings or caching headers. In this case, the server administrator may need to review the server configuration and ensure that caching is properly configured and headers are being set correctly.
What is the difference between a 200 status code and a 304 status code?
A 200 status code and a 304 status code both indicate a successful request, but they have different meanings and purposes.
A 200 status code is a standard HTTP response that indicates that the requested resource was successfully retrieved and is being returned in the response. It indicates that the server has processed the request and is sending back the resource that was requested by the client.
A 304 status code, on the other hand, is not a response containing the requested resource. Instead, it indicates that the requested resource has not been modified since the last time the client retrieved it, and the client can use its cached version of the resource. The server is not sending the requested resource again in the response, but instead instructs the client to use the cached version that it already has.
In other words, a 200 status code means that the server is sending the requested resource in the response, while a 304 status code means that the server is not sending the requested resource again because the client already has a current version of the resource in its cache.
Does a 304 status code affect search engine optimization (SEO)?
A 304 status code does not directly affect search engine optimization (SEO), as it is not an error code but rather a response indicating that the requested resource has not been modified since the client’s cached version of the resource.
However, the use of caching and the appropriate use of 304 status codes can indirectly affect SEO by improving website performance and user experience. By reducing the number of requests and responses exchanged between the client and server, caching can help speed up page load times, which can positively impact SEO.
In addition, the use of 304 status codes in conjunction with caching can help reduce server load and bandwidth usage, which can also have a positive impact on website performance and SEO.
Overall, the use of 304 status codes and caching can indirectly contribute to better website performance, which can have a positive impact on user experience and indirectly impact SEO.
Additional resources
- Learn about web development
- Learn about SEO
- Web development services from WebFX
- SEO services from WebFX
- MDN Web Docs
- W3Schools
Marketing Tips for Niche Industries
- Tourism/hospitality Statistics
- Treat More Patients with Healthcare Marketing Services
- Urgent Care Marketing Ideas: 5 High-ROI Tactics
- WebFX: Your Education Digital Marketing Agency
- Why Auto Part Retailers Need Digital Marketing
- Why Digital Marketing is Essential for Auctioneers
- Your Guide to Digital Marketing for Exercise Equipment Companies
- Vision Care Industry Statistics
- 10 Best Orthodontist Marketing Ideas to Earn More Patients
- 10 Digital Marketing Strategies for the Heavy Equipment Industry