Performance: 404 Not Found handler
MEDIUM IMPACT
This affects the server response time and user experience when a requested resource is missing.
const path = require('path'); app.use((req, res) => { res.status(404).sendFile(path.join(__dirname, 'public', '404.html')); });
app.use((req, res) => {
res.status(404).send('<html><body><h1>Page not found</h1></body></html>');
});| Pattern | Server CPU Usage | Response Time | Caching | Verdict |
|---|---|---|---|---|
| Inline HTML string in handler | High (blocks event loop if complex) | Slower (builds string every request) | No caching | [X] Bad |
| Serve static 404 HTML file | Low (non-blocking streaming) | Faster (cached by browser/server) | Yes, effective caching | [OK] Good |