Performance: Setting response headers
MEDIUM IMPACT
Setting response headers affects how quickly the browser can start rendering content and how efficiently resources are cached or processed.
const http = require('http'); http.createServer((req, res) => { res.setHeader('Content-Type', 'text/html'); res.setHeader('Cache-Control', 'public, max-age=31536000'); res.end('<h1>Hello</h1>'); }).listen(3000);
const http = require('http'); http.createServer((req, res) => { res.setHeader('Content-Type', 'text/html'); res.setHeader('Cache-Control', 'no-cache'); res.end('<h1>Hello</h1>'); }).listen(3000);
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No caching headers or 'no-cache' | N/A | N/A | Blocks rendering until network response | [X] Bad |
| Proper Content-Type and long max-age caching | N/A | N/A | Allows fast rendering from cache | [OK] Good |