304 Not Modified
Fault: Neither
TL;DR
Use cached version of the resource.
The resource has not been modified since the last request.
What This Error Means
The resource has not been modified since the last request.
Use cached version of the resource.
Common Causes
- If-Modified-Since conditional request
- ETag validation
- Resource unchanged
How to Fix It (For Visitors)
- Browser uses cached version
How to Fix It (For Developers/Admins)
- Implement ETag and Last-Modified headers
- Support conditional requests
Code Examples
Here's how to return a 304 status code in various programming languages:
Python (Flask)
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/endpoint')
def endpoint():
return jsonify({"message": "Not Modified"}), 304
Node.js (Express)
const express = require('express');
const app = express();
app.get('/endpoint', (req, res) => {
res.status(304).json({ message: 'Not Modified' });
});
PHP
<?php
http_response_code(304);
header('Content-Type: application/json');
echo json_encode(['message' => 'Not Modified']);
?>
Go
package main
import (
"encoding/json"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(304)
json.NewEncoder(w).Encode(map[string]string{
"message": "Not Modified",
})
}
Java (Spring Boot)
@GetMapping("/endpoint")
public ResponseEntity<Map<String, String>> endpoint() {
Map<String, String> response = new HashMap<>();
response.put("message", "Not Modified");
return ResponseEntity.status(304).body(response);
}
Ruby (Sinatra)
get '/endpoint' do
status 304
json message: 'Not Modified'
end
Browser Compatibility
| Browser | Support | Notes |
|---|---|---|
| Chrome | ✓ Full Support | All versions |
| Firefox | ✓ Full Support | All versions |
| Safari | ✓ Full Support | All versions |
| Edge | ✓ Full Support | All versions |
Official Specification
This status code is defined in RFC 7232 Section 4.1.