Performance: Route handlers (route.ts)
MEDIUM IMPACT
This affects server response time and initial page load speed by controlling how requests are handled and data is fetched.
export async function GET(request) { const data = await fetch('https://external-api.com/data', { next: { cache: 'force-cache' } }); const json = await data.json(); return new Response(JSON.stringify(json)); }
export async function GET(request) { const data = await fetch('https://external-api.com/data'); const json = await data.json(); return new Response(JSON.stringify(json)); }
| Pattern | Server Processing | Network Delay | Response Time | Verdict |
|---|---|---|---|---|
| No caching, external API fetch on every request | High CPU and wait time | High due to external call | Slow (200-500ms+) | [X] Bad |
| Cached data fetch in route handler | Low CPU, fast retrieval | Low network delay | Fast (<50ms on repeated calls) | [OK] Good |