Performance: Why authentication matters
MEDIUM IMPACT
Authentication affects initial page load speed and interaction responsiveness by adding server-side checks and potential redirects.
app.use(async (req, res, next) => { try { const user = await asyncAuthCheck(req.headers.authorization); if (!user) { return res.status(401).send('Unauthorized'); } next(); } catch (err) { next(err); } });
app.use((req, res, next) => {
// Synchronous heavy authentication check
const user = heavyAuthCheck(req.headers.authorization);
if (!user) {
return res.status(401).send('Unauthorized');
} else {
next();
}
});| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous blocking auth | N/A (server-side) | N/A | Delays initial paint | [X] Bad |
| Asynchronous non-blocking auth | N/A (server-side) | N/A | Faster initial paint | [OK] Good |