Performance: How Next.js renders (server-first model)
HIGH IMPACT
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 |