Performance: Dynamic route parameters
MEDIUM IMPACT
Dynamic route parameters affect page load speed by determining which content to fetch and render based on the URL, impacting initial rendering and navigation responsiveness.
export async function load({ params }) { const id = params.id; const item = await fetch(`/api/items/${id}`).then(res => res.json()); return { item }; }
export async function load({ params }) { const id = params.id; const data = await fetch('/api/items').then(res => res.json()); return { item: data.find(i => i.id === id) }; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Fetch all data then filter | High (many nodes if rendering all) | Multiple reflows as content updates | High paint cost due to large DOM | [X] Bad |
| Fetch only needed data by parameter | Low (only relevant nodes) | Single reflow on content insert | Low paint cost with small DOM | [OK] Good |