On this page
A 204 response when clicking a link can make a working endpoint look broken: the server reports success, but sends no page for the browser to display. If the link is supposed to open a document or confirmation page, the response may be valid HTTP but unsuitable for that interaction.
This guide shows how to diagnose the response locally and choose a better status for page navigation, form submission, or JavaScript requests. The example was not executed in this environment, and RFC 9110 could not be consulted here; verify the behavior in your target browser and review the standard before relying on protocol details.
Key Takeaways
204 No Contentsignals a successful response with no response content. It is not a page for the browser to render.- Browser navigation behavior can vary; do not assume every browser handles a 204 navigation identically.
- Return
200 OKwith a document when a link should display a page. After a form submission, a303 See Otherredirect can lead to a confirmation page. - A 204 can be useful for a JavaScript
fetchrequest when the client needs a success signal but no response body.
Why the link appears to do nothing
A normal link navigation asks the browser to visit a URL. If the endpoint returns an HTML document, the browser has content to display. If it returns 204, there is no response content to render. Depending on the browser and context, the existing page may remain visible, making the click look ineffective even though the server returned a successful status.
That is different from a network failure or a 404 Not Found. Check the navigation request's status in the browser's developer tools before assuming the link or click handler is broken.
A 204 response must not contain a message body. Do not return HTML alongside it and expect that HTML to become the destination page.
Advertisement
Reproduce the response locally
The following Python example provides a page with a link to a 204 endpoint, a link to a normal page, a form, and a fetch button. It requires Python and uses only its standard library. It is a diagnostic example, not a production server; the POST endpoint does not save anything.
Save this as server.py:
from http.server import BaseHTTPRequestHandler, HTTPServer
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == "/empty":
self.send_response(204)
self.send_header("Cache-Control", "no-store")
self.end_headers()
return
if self.path == "/":
self.send_html("""<!doctype html>
<html lang="en">
<head><meta charset="utf-8"><title>204 navigation demo</title></head>
<body>
<p><a href="/empty">Navigate to a 204 response</a></p>
<p><a href="/page">Navigate to a normal page</a></p>
<form action="/save" method="post">
<button type="submit">Submit form and receive 204</button>
</form>
<p><button id="request" type="button">Send fetch request</button></p>
<p id="result" role="status"></p>
<script>
document.querySelector('#request').addEventListener('click', async () => {
const result = document.querySelector('#result');
try {
const response = await fetch('/save', { method: 'POST' });
result.textContent = response.status === 204
? 'Request succeeded; no response content.'
: `Unexpected status: ${response.status}`;
} catch (error) {
result.textContent = `Request failed: ${error.message}`;
}
});
</script>
</body>
</html>""")
return
if self.path == "/page":
self.send_html("""<!doctype html>
<html lang="en">
<head><meta charset="utf-8"><title>Destination</title></head>
<body><h1>Destination page</h1><p>The server returned a document.</p></body>
</html>""")
return
self.send_error(404)
def do_POST(self):
if self.path != "/save":
self.send_error(404)
return
self.send_response(204)
self.send_header("Cache-Control", "no-store")
self.end_headers()
def send_html(self, document):
body = document.encode("utf-8")
self.send_response(200)
self.send_header("Content-Type", "text/html; charset=utf-8")
self.send_header("Content-Length", str(len(body)))
self.send_header("Cache-Control", "no-store")
self.end_headers()
self.wfile.write(body)
if __name__ == "__main__":
server = HTTPServer(("127.0.0.1", 8000), Handler)
try:
server.serve_forever()
except KeyboardInterrupt:
pass
finally:
server.server_close()
Start it with python3 server.py, then open http://127.0.0.1:8000/ in a browser. Stop the server with Ctrl+C when finished.
Check it in a browser
- Open developer tools and select the Network panel. Enable request-log preservation if your browser offers it.
- Click Navigate to a 204 response. Inspect the navigation request: the server code is intended to return status 204 without a body. Note what your browser displays and whether the address changes; do not assume that result applies to every browser.
- Return to the starting page if necessary, then click Navigate to a normal page. Inspect the
200response and its HTML document. - Submit the form and inspect the POST response. Then try the fetch button: its JavaScript handles the 204 by updating text on the existing page rather than navigating.
If your observations differ, record the browser and version, check which request was selected in the Network panel, and confirm that no extension, proxy, or application code is changing the interaction.
Check it with an HTTP client
In another terminal, use curl to inspect the response headers and any body:
curl -i http://127.0.0.1:8000/empty
curl -i http://127.0.0.1:8000/page
curl -i -X POST http://127.0.0.1:8000/save
The code is intended to send 204 with no body for the first and third requests, and 200 with an HTML body for the second. Curl shows the HTTP response; it does not reproduce the browser's navigation or rendering behavior.
Advertisement
Choose a response for the interaction
A link should show a page
Return 200 OK with an appropriate document and content type when the destination itself is a page. If the endpoint should send the visitor elsewhere instead, use an appropriate redirect with a Location header. A 204 is not a substitute for either a document or a redirect.
A form should show a result
A form submission can receive a 204 when no response content is needed, but that gives the browser no confirmation document to render. If the user needs a visible result or a new page, return a document or redirect after a successful submission. A common pattern is 303 See Other with a Location header pointing to a confirmation page, which the browser can request with GET.
Do not use the demo's /save endpoint as evidence that anything was persisted: it only demonstrates a response.
JavaScript needs a success signal, not a page
For a fetch request, 204 can be a good fit when the operation succeeds and there is nothing to return. The calling script can update the existing interface, as the example does. Check the status before trying to parse JSON: a 204 provides no JSON document to parse. Also handle non-success statuses and network errors according to the application's needs.
Common Mistakes
- Treating 204 as an error automatically. It is a success status; the issue may be a mismatch between the response and the expected user experience.
- Sending a body with 204. Choose a status that permits response content if the client needs HTML or JSON.
- Assuming curl proves browser behavior. Inspect the HTTP response with curl, then separately test navigation in the browsers you support.
- Assuming a form or fetch request navigates in the same way. A form submission is a browser navigation;
fetchreturns a response to JavaScript and does not itself navigate the page. - Expecting a visible confirmation from an empty response. Provide a document, redirect, or client-side feedback when users need to know what happened.
Best Practices
- Define the expected user-visible result for each browser-facing endpoint before choosing its status code.
- In developer tools, inspect the actual request, response status, headers, and any redirect chain. Compare that evidence with server logs where available.
- Test direct navigation, form submissions, and scripted requests separately in the supported browser environments.
- For state-changing operations, use an appropriate method and apply the application's authentication, authorization, and request-forgery protections. A successful status alone does not establish that those safeguards exist.
Conclusion
A 204 can be a correct success response while still being the wrong response for a link expected to show a page. Inspect the request, test the browser behavior, and return a document or redirect when navigation needs a visible destination.
What would your domain sell for?
A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.