Performance: Static export option
HIGH IMPACT
This affects the page load speed by pre-generating HTML at build time, reducing server work and improving initial content display.
export async function getStaticProps() { const res = await fetch('https://example.com/api/data'); const data = await res.json(); return { props: { data } }; } export default function Page({ data }) { return <div>{data.content}</div>; }
export default function Page() { const [data, setData] = React.useState(null); React.useEffect(() => { fetch('/api/data').then(res => res.json()).then(setData); }, []); if (!data) return <p>Loading...</p>; return <div>{data.content}</div>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Client-side data fetch | Minimal initially, but updates DOM after fetch | Triggers at least 1 reflow after data arrives | Paint delayed until data fetch completes | [X] Bad |
| Static export with getStaticProps | Full DOM ready on load | No reflows caused by data fetching | Paint happens immediately with full content | [OK] Good |