Performance: Request context middleware
MEDIUM IMPACT
This affects server response time and throughput by adding processing steps per request.
app.use((req, res, next) => {
// Initialize empty context
req.context = {};
next();
});
app.get('/route', async (req, res) => {
if (!req.context.data) {
req.context.data = await fetchDataAsync();
}
res.send(req.context.data);
});app.use((req, res, next) => {
// Heavy synchronous computation
const data = expensiveSyncFunction();
req.context = { data };
next();
});| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy synchronous middleware | N/A | N/A | N/A | [X] Bad |
| Lightweight async middleware | N/A | N/A | N/A | [OK] Good |