Performance: Svelte components in Astro
This affects page load speed and interaction responsiveness by how Svelte components are hydrated and rendered within Astro pages.
--- import MyWidget from '../components/MyWidget.svelte'; --- <html> <body> <MyWidget client:idle /> <MyWidget client:idle /> <MyWidget client:idle /> </body> </html>
--- import MyWidget from '../components/MyWidget.svelte'; --- <html> <body> <MyWidget client:load /> <MyWidget client:load /> <MyWidget client:load /> </body> </html>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| client:load on many components | Multiple hydration scripts | Multiple reflows during hydration | High paint cost due to JS blocking | [X] Bad |
| client:idle on many components | Same DOM but deferred hydration | Single reflow after idle hydration | Lower paint cost, smoother interaction | [OK] Good |
Svelte components inside an Astro project?Button.svelte in an Astro file?import Component from './Component.svelte'..svelte and is imported as default export.import Button from './Button.svelte'; [OK]--- import Counter from './Counter.svelte'; ---
Counter.svelte shows the starting number inside a <p> tag.start={5} are passed to Svelte components as expected.start prop inside a paragraph, so it shows 5.--- import MyButton from './MyButton.svelte' ---
Toggle.svelte inside an Astro page that changes text on click. Which steps are needed to make it interactive inside Astro?Toggle.svelte and use it as a tag in Astro frontmatter and template.client:load or similar directive to tell Astro to hydrate the component on the client for interactivity.client:load directive on the tag for hydration -> Option APass the test and this pattern moves unknown