Performance: Why Astro excels at performance
Astro improves page load speed and interaction responsiveness by sending less JavaScript to the browser and rendering mostly static HTML.
---
const message = 'Hello';
---
<html><body><h1>{message}</h1></body></html><script type="module">import React from 'react'; export default function App() { return <div>Hello</div>; }</script> <script type="module">import ReactDOM from 'react-dom'; ReactDOM.render(<App />, document.getElementById('root'));</script>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Full client-side React app | Many nodes created dynamically | Multiple reflows during hydration | High paint cost due to JS-driven updates | [X] Bad |
| Astro static HTML with partial hydration | Static DOM nodes from server | Single reflow on initial load | Low paint cost, minimal JS | [OK] Good |
client:load or client:visible to load JavaScript only when needed.<MyComponent client:visible>...</MyComponent> is the correct way to load JS when the component becomes visible.<MyWidget client:idle />
MyWidget?client:idle directive tells Astro to load the JavaScript when the browser is idle, not immediately.client:load, never loading is incorrect, and loading on click is client:click.<MyComponent client:load />
client:load is a valid directive, so the issue is not the directive itself.client:visible directive loads JavaScript only when the widget scrolls into view, saving resources.Pass the test and this pattern moves unknown