Performance: req.headers for HTTP headers
LOW IMPACT
Accessing req.headers affects server-side request processing speed and can indirectly impact response time.
app.get('/', (req, res) => { const userAgent = req.headers['user-agent']; // simple check or cache results if possible const isMobile = userAgent.includes('Mobile'); res.send(`Mobile: ${isMobile}`); });
app.get('/', (req, res) => { const userAgent = req.headers['user-agent']; // parsing userAgent multiple times or complex regex const isMobile = /Mobile/.test(userAgent); const isChrome = /Chrome/.test(userAgent); res.send(`Mobile: ${isMobile}, Chrome: ${isChrome}`); });
| Pattern | CPU Usage | Request Latency | Memory Impact | Verdict |
|---|---|---|---|---|
| Complex regex parsing on headers | High | Increased by ms | Low | [X] Bad |
| Simple string checks on headers | Low | Minimal increase | Low | [OK] Good |