Performance: Why Astro ships zero JavaScript by default
This affects page load speed by reducing the amount of JavaScript sent to the browser, improving initial load and interactivity.
export default function Page() {
return <h1>Hello, static content!</h1>;
}import HeavyComponent from './HeavyComponent.jsx'; export default function Page() { return <HeavyComponent />; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Shipping all JS by default | High (many nodes from JS components) | Multiple reflows due to JS execution | High paint cost from dynamic content | [X] Bad |
| Shipping zero JS by default | Low (static HTML only) | Single initial reflow | Low paint cost with static content | [OK] Good |
client:load to add JavaScript loading behavior.<MyComponent client:load /> uses the correct client:load syntax.<MyWidget client:idle />
client:idle directive loads JavaScript when the browser is idle.<MyButton client:load>Click</MyButton>
client:load requires the component to have JavaScript to load.MyButton has no JavaScript, the directive does nothing.client:load only to the button loads JS just where needed.Pass the test and this pattern moves unknown