Performance: Server endpoints (API routes)
This affects the time it takes for the server to respond and the page to load dynamic data, impacting initial load and interaction speed.
let cachedData; export async function GET() { if (!cachedData) { const data = await fetch('https://external-api.com/data'); cachedData = await data.json(); } return new Response(JSON.stringify(cachedData)); }
export async function GET() { const data = await fetch('https://external-api.com/data'); const json = await data.json(); return new Response(JSON.stringify(json)); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No caching, external API call on every request | N/A (server-side) | N/A | Delays initial paint | [X] Bad |
| Cached data in server memory | N/A (server-side) | N/A | Faster initial paint | [OK] Good |
export async function GET() {
return new Response(JSON.stringify({ message: 'Hi' }), { headers: { 'Content-Type': 'application/json' } })
}export function POST(request) {
const data = await request.json();
return new Response('Received');
}Pass the test and this pattern moves unknown