Performance: Status codes and headers
This affects how quickly the browser understands the server response and how efficiently it processes caching and content rendering.
res.status(200).set({ 'Cache-Control': 'public, max-age=3600' }).send(data);
res.status(200).send(data); // No caching headers or incorrect status code for errors
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No caching headers, incorrect status codes | N/A | 0 | 0 | [X] Bad |
| Correct status codes with caching headers | N/A | 0 | 0 | [OK] Good |
201 usually indicate in a response?X-Custom-Header with value 123 in a NestJS controller using Express response?res.set() to set headers.res.set() accepts header name and string value. res.set('X-Custom-Header', '123'); uses correct method and string value.async getData(@Res() res) {
res.status(204).set('X-Info', 'No Content').send();
}async update(@Res() res) {
res.status(200);
res.set('Content-Type', 'application/json');
res.send({ success: true });
res.status(201);
}X-Request-ID and a JSON body in NestJS. Which code snippet correctly achieves this?Pass the test and this pattern moves unknown