Performance: Purpose of forms
MEDIUM IMPACT
Forms affect page interactivity and input responsiveness, impacting how quickly users can submit data and receive feedback.
<form action="/submit" method="post" onsubmit="validateAndSubmitAsync(event)"> <input type="text" name="username"> <button type="submit">Submit</button> </form> <script> async function validateAndSubmitAsync(event) { event.preventDefault(); // lightweight async validation await new Promise(resolve => setTimeout(resolve, 10)); event.target.submit(); } </script>
<form action="/submit" method="post" onsubmit="return validateAndSubmit()"> <input type="text" name="username"> <button type="submit">Submit</button> </form> <script> function validateAndSubmit() { // heavy synchronous validation for(let i=0; i<1000000000; i++) {} return true; } </script>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous heavy validation on submit | Minimal | 0-1 (if DOM updated) | Low to medium (if blocking) | [X] Bad |
| Asynchronous validation with minimal DOM changes | Minimal | 0 | Low | [OK] Good |