Performance: Component structure (frontmatter + template)
This affects the initial page load speed and rendering performance by controlling how much JavaScript and HTML are processed and sent to the browser.
---
const items = Astro.props.items;
---
<ul>
{items.map(item => <li>{item.name}</li>)}
</ul>--- const data = await fetch('https://api.example.com/data'); const items = await data.json(); --- <ul> {items.map(item => <li>{item.name}</li>)} </ul>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy async logic in frontmatter | Minimal DOM nodes but delayed HTML | 0 immediate reflows but delayed rendering | Paint delayed due to late HTML | [X] Bad |
| Simple frontmatter with props | Minimal DOM nodes, fast HTML output | 0 reflows, fast paint | Paint happens quickly after HTML arrives | [OK] Good |
--- at the top and bottom to mark the frontmatter section.--- const greeting = "Hello, Astro!"; ---{greeting}
greeting is defined in frontmatter with value "Hello, Astro!".{greeting} to insert the variable's value into the HTML.--- const name = "Astro";Hello, {name}!
---
--- lines.<h1> is inside frontmatter, causing an error.fruits array.map() returns an array of JSX elements to render.--- const fruits = ["Apple", "Banana", "Cherry"]; ---
map() correctly to return <li> elements. --- const fruits = ["Apple", "Banana", "Cherry"]; ---
--- const fruits = ["Apple", "Banana", "Cherry"]; ---
forEach() which returns undefined. --- const fruits = ["Apple", "Banana", "Cherry"]; ---
Pass the test and this pattern moves unknown