Performance: What is Astro
Astro affects page load speed by delivering minimal JavaScript and optimizing content rendering for faster initial paint.
--- Astro component --- --- const message = 'Hello World'; --- <html> <body> <h1>{message}</h1> </body> </html> // Astro renders static HTML with zero JS by default
import React from 'react'; export default function Page() { return <div>Hello World</div>; } // This React component ships full React runtime and JS to client
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| React full client render | High (many nodes) | Multiple reflows | High paint cost | [X] Bad |
| Astro static HTML | Low (simple DOM) | Single reflow | Low paint cost | [OK] Good |
<script> block exporting default to define behavior.<Component>Hello</Component> <script>export default {};</script> shows HTML markup with a <script> exporting default, which is correct. <Component>Hello</Component> lacks script, B is React style, C is just HTML without component structure.<script>
export let name = 'Friend';
</script>
<h1>Hello, {name}!</h1>name has a default value 'Friend' if no prop is passed.name remains 'Friend', so the output is <h1>Hello, Friend!</h1>.<script>
let count = 0;
</script>
<button onClick={() => count++}>Click</button>
<p>Count: {count}</p><script> block to receive the list, then a map in the markup with a condition to add a CSS class for long names uses Astro's built-in features to map and conditionally style names, which is simple and efficient. Using React inside Astro adds unnecessary complexity, writing plain HTML with no scripting is static, and creating a server-side API is overkill for this task.<script> block to receive the list, then use a map in the markup with a condition to add a CSS class for long names [OK]Pass the test and this pattern moves unknown