Performance: Dynamic route parameters
MEDIUM IMPACT
Dynamic route parameters affect how quickly the server and client can resolve and render the correct page content based on URL changes.
export const loader = async ({ params }) => { const cachedData = cache.get(params.id); if (cachedData) return cachedData; const response = await fetch(`/api/items/${params.id}`); const data = await response.json(); cache.set(params.id, data); return data; }; // Uses caching to avoid repeated fetches on same parameter
export const loader = async ({ params }) => { const data = await fetch(`/api/items/${params.id}`); return data.json(); }; // In route file: routes/items/$id.jsx // No caching or prefetching, fetches on every navigation
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No caching dynamic route data fetch | Minimal DOM changes | 1 reflow per navigation | Medium paint cost due to delayed data | [X] Bad |
| Cached dynamic route data fetch | Minimal DOM changes | 1 reflow per navigation | Lower paint cost due to faster data | [OK] Good |