Performance: Static export option
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 |
next export command do in a Next.js project?next exportnext export command creates static HTML files from your Next.js app, making it server-free.next dev or next build, next export does not start a server or do server-side rendering on request.next.config.js?output: 'export' in next.config.js to enable static export mode.exportStatic or staticExport are not valid Next.js config keys.next export?
export default function Home() {
return <h1>Welcome to Static Export</h1>;
}getStaticProps.next export but get an error: "Pages with getServerSideProps can not be exported." How do you fix this?getServerSideProps because it requires server-side rendering on each request.getServerSideProps with getStaticProps or remove it to allow static export./posts/[id]. Which approach works best with static export?getStaticPaths.getStaticProps to fetch data at build timegetStaticPaths and getStaticProps pre-generates all pages for export.Pass the test and this pattern moves unknown