Performance: Why components are the building blocks
MEDIUM IMPACT
This concept affects how efficiently the page loads and updates by controlling how much of the UI the browser must render or re-render.
<script> import Counter from './Counter.svelte'; </script> <div> <Counter /> <p>Other unrelated content</p> </div> <!-- Counter.svelte --> <script> let count = 0; </script> <button on:click={() => count++}>Click me</button> <p>{count}</p>
<script> let count = 0; </script> <div> <button on:click={() => count++}>Click me</button> <p>{count}</p> <p>Other unrelated content</p> </div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Single large component | Many nodes updated on any change | Multiple reflows per update | High paint cost | [X] Bad |
| Small isolated components | Only relevant nodes updated | Single reflow per component update | Low paint cost | [OK] Good |