Performance: Response formatting
MEDIUM IMPACT
Response formatting affects how quickly the server sends data and how efficiently the browser processes it, impacting page load speed and interaction readiness.
export default function handler(req, res) { const data = { message: 'Hello World', time: new Date().toISOString() }; res.json(data); }
export default function handler(req, res) { const data = { message: 'Hello World', time: new Date() }; res.setHeader('Content-Type', 'application/json'); res.send(JSON.stringify(data)); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual JSON.stringify with extra data | N/A | 0 | Low but delayed by parsing | [X] Bad |
| res.json with minimal data | N/A | 0 | Low and fast parsing | [OK] Good |