While I was testing a weird behaviour in cache handling with Chrome (I asked something about it here), I found something else: Chrome dev tool shows a 200 status code when the server returns a 304 response.
Here you can see what chrome dev tool says (200) and I included a wireshark capture that shows the server 304 response.
Here is the same usage with Firefox, which shows the 304 code :
More interesting is the timing difference between the two browsers :
Firefox doesn't shows delay for the reception part but Chrome says it took 3.91ms.
Do you have any idea on why Chrome doesn't shows the right status code?
If you want to test yourself, here is the server code:
#!/usr/bin/env node
'use strict';
const express = require('express');
const cors = require('cors');
const compression = require('compression');
const pathUtils = require('path');
const fs = require('fs');
const http = require('http');
let app = express();
app.disable('x-powered-by');
app.use(express.json({ limit: '50mb' }));
app.use(cors());
app.use(compression({}));
app.use(function (req, res, next) {
res.set('Cache-control', 'no-cache');
console.log(req.headers);
next();
});
let server = http.createServer(app);
app.get('/api/test', (req, res) => {
res.status(200).send(fs.readFileSync(pathUtils.join(__dirname, 'dummy.txt')));
});
server.listen(1234);
and the client :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
let test = fetch('http://localhost:1234/api/test').then((res) => {
console.log(res.status);
return res.text();
});
</script>
</body>
</html>
An HTTP 304 not modified status code means that the website you're requesting hasn't been updated since the last time you accessed it. Typically, your browser will save (or cache) web pages so it doesn't have to repeatedly download the same information. This is an attempt to speed up page delivery.
# Open the Issues tab Open DevTools. Click the Go to Issues button in the yellow warning bar. Alternatively, select Issues from the More tools menu. Once you're on the Issues tab, click the Reload page button if necessary.
The HTTP 304 Not Modified client redirection response code indicates that there is no need to retransmit the requested resources. It is an implicit redirection to a cached resource.
If it shows 200 I can't know it is actually 304 without looking into request detail. Compared to Firefox (the same request), 304 in status code. To make my question clear (based on an answer I got), I believe Chrome got the result from cache, after all that is what 304 is for. So why did Chrome showed 200 then? Show activity on this post.
To understand HTTP 304, it helps to first understand status codes. Put simply, every time you make a request to your browser – such as by accessing a particular website – an HTTP status code is sent between your browser and the server in order to exchange information.
The most common causes include: A cached resource that is infected or corrupted (i.e., malware or viruses affecting the browser) The 304 status code can be due to a problem on either the server-side or the client-side, so it might take some troubleshooting in order to diagnose and resolve it.
The Internet Engineering Task Force (IETF) defines the 304 Not Modified as: The 304 (Not Modified) status code indicates that 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.
I think that's actually a chrome bug. A bug report has been opened here : https://bugs.chromium.org/p/chromium/issues/detail?id=1269602
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With