Performance: Status code conventions
This affects how quickly browsers and clients understand server responses, impacting perceived responsiveness and error handling.
Jump into concepts and practice - no test required
app.get('/data', (req, res) => { res.status(404).send({ error: 'Not found' }); });
app.get('/data', (req, res) => { res.status(200).send({ error: 'Not found' }); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Incorrect status codes (e.g., 200 on error) | No direct DOM impact | No reflows | No paint cost | [!] OK but causes client delays |
| Correct status codes (e.g., 404, 500) | No direct DOM impact | No reflows | No paint cost | [OK] Improves client handling and responsiveness |
app.get('/data', (req, res) => {
res.status(201).send('Created');
});app.post('/submit', (req, res) => {
if (!req.body.name) {
res.status(400);
res.send('Name is required');
}
});