Performance: Functional middleware
MEDIUM IMPACT
Functional middleware affects request processing speed and server response time by controlling how requests flow through the middleware stack.
export function fastMiddleware(req, res, next) {
// Non-blocking async operation example
setImmediate(next);
}export function slowMiddleware(req, res, next) {
// Simulate heavy synchronous task
const start = Date.now();
while (Date.now() - start < 100) {}
next();
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Blocking synchronous middleware | N/A (server-side) | N/A | N/A | [X] Bad |
| Non-blocking async middleware | N/A (server-side) | N/A | N/A | [OK] Good |