Performance: Default actions
MEDIUM IMPACT
This concept affects how quickly user interactions respond and how smoothly the page updates after events.
function handleClick(event) { // Let default action happen immediately console.log('Immediate action'); // Run slow code asynchronously without blocking setTimeout(() => { console.log('Delayed action'); }, 1000); } <button on:click={handleClick}>Click me</button>
function handleClick(event) { event.preventDefault(); // heavy computation or slow code here setTimeout(() => { console.log('Delayed action'); }, 1000); } <button on:click={handleClick}>Click me</button>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Blocking default action with heavy JS | Minimal | 0 immediate, delayed reflows possible | Low immediate, higher delayed | [X] Bad |
| Allowing default action, async heavy JS | Minimal | 0 immediate | Low | [OK] Good |