Performance: How Next.js renders (server-first model)
This affects the initial page load speed and time to first meaningful paint by rendering content on the server before sending it to the browser.
export const dynamic = 'force-static'; async function Page() { const data = await fetch('https://api.example.com/data').then(res => res.json()); return <div>{data.message}</div>; } export default Page;
import React from 'react'; 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.message}</div>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Client-side data fetching after load | Many (dynamic nodes created after JS runs) | Multiple reflows as content loads | High paint cost due to delayed content | [X] Bad |
| Server-first rendering with pre-fetched data | Minimal (static HTML nodes) | Single reflow on initial paint | Low paint cost with immediate content | [OK] Good |
export async function getServerSideProps() {
return { props: { message: 'Hello from server' } };
}
export default function Page({ message }) {
return <h1>{message}</h1>;
}export async function getServerSideProps() {
const data = await fetch('https://api.example.com/data');
return { props: { data } };
}
export default function Page({ data }) {
return <div>{data.title}</div>;
}Pass the test and this pattern moves unknown