Performance: Why template syntax renders dynamic content
MEDIUM IMPACT
This affects how quickly dynamic content appears on the page and how efficiently the browser updates the UI when data changes.
<script> let count = 0; </script> <p>{count}</p> <button on:click={() => count++}>Increment</button>
<script> let count = 0; </script> <p>{count}</p> <button on:click={() => { count++; document.querySelector('p').textContent = count; }}>Increment</button>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual DOM update on event | Multiple direct DOM writes | Triggers reflow on each update | High paint cost due to forced layout | [X] Bad |
| Svelte template reactive update | Minimal DOM updates via reactive bindings | Single reflow per change | Low paint cost with efficient diffing | [OK] Good |