Performance: Manual validation patterns
MEDIUM IMPACT
Manual validation patterns affect server response time and user experience by adding synchronous or asynchronous checks before processing requests.
function validateInput(data) {
if (!data.email || !data.password) return 'Missing fields';
if (data.password.length < 8) return 'Password too short';
return null;
}
app.post('/submit', (req, res) => {
const error = validateInput(req.body);
if (error) {
res.status(400).send(error);
return;
}
res.send('Success');
});app.post('/submit', (req, res) => { if (!req.body.email || !req.body.password) { res.status(400).send('Missing fields'); return; } if (req.body.password.length < 8) { res.status(400).send('Password too short'); return; } // further processing res.send('Success'); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual inline validation with multiple response calls | 0 (server-side) | 0 | 0 | [X] Bad |
| Centralized synchronous validation function | 0 (server-side) | 0 | 0 | [OK] Good |
| Inline async validation with multiple awaits | 0 (server-side) | 0 | 0 | [X] Bad |
| Encapsulated async validation function | 0 (server-side) | 0 | 0 | [OK] Good |