Performance: Applying middleware to routes
MEDIUM IMPACT
Middleware affects the request processing speed and can impact the time before the route handler executes, influencing interaction responsiveness.
app.use('/api/users', userMiddleware); // applies middleware only to /api/users routesapp.use(globalMiddleware); // applies middleware to every route
| Pattern | Middleware Runs | Processing Overhead | Response Delay | Verdict |
|---|---|---|---|---|
| Global middleware on all routes | Every request | High | Increased INP latency | [X] Bad |
| Middleware applied to specific routes | Only targeted requests | Low | Minimal delay | [OK] Good |