Performance: Dynamic route segments
MEDIUM IMPACT
This affects the page load speed and server response time by determining how routes are matched and pages are rendered dynamically.
export async function getStaticPaths() { const res = await fetch('https://api.example.com/users'); const users = await res.json(); const paths = users.map(user => ({ params: { id: user.id.toString() } })); return { paths, fallback: 'blocking' }; } export async function getStaticProps({ params }) { const res = await fetch(`https://api.example.com/users/${params.id}`); const user = await res.json(); return { props: { user }, revalidate: 60 }; } export default function UserPage({ user }) { return <div>{user.name}</div>; }
export async function getServerSideProps(context) { const { id } = context.params; const res = await fetch(`https://api.example.com/users/${id}`); const user = await res.json(); return { props: { user } }; } export default function UserPage({ user }) { return <div>{user.name}</div>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Server-side rendering on every request | Minimal DOM nodes | 1 reflow per page load | High paint cost due to blocking | [X] Bad |
| Static generation with fallback blocking | Minimal DOM nodes | 1 reflow per page load | Low paint cost, fast rendering | [OK] Good |