Performance: Why API routes serve data endpoints
MEDIUM IMPACT
This affects how fast data loads on the page and how responsive the app feels when fetching or sending data.
export const GET = async () => { const data = await fetchExternalData(); return new Response(JSON.stringify(data), { headers: { 'Content-Type': 'application/json' } }); }; // API route serves data endpoint separately, page fetches from this route asynchronously.
export async function load() { const res = await fetch('https://external-api.com/data'); const data = await res.json(); return { data }; } // This fetches data directly in the page load, blocking rendering until data arrives.
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Direct fetch in page load | Minimal | 1 (delayed) | High (blocks paint) | [X] Bad |
| API route serving data endpoint | Minimal | 1 (async after render) | Low (non-blocking) | [OK] Good |