Performance: Server load functions (+page.server.js)
MEDIUM IMPACT
This affects the server response time and initial page load speed by controlling data fetching before the page renders.
export async function load() { const [res1, res2] = await Promise.all([ fetch('https://api.example.com/data1'), fetch('https://api.example.com/data2') ]); const data1 = await res1.json(); const data2 = await res2.json(); return { data1, data2 }; }
export async function load() { const res1 = await fetch('https://api.example.com/data1'); const data1 = await res1.json(); const res2 = await fetch('https://api.example.com/data2'); const data2 = await res2.json(); return { data1, data2 }; }
| Pattern | Server Fetches | Parallelism | Server Response Time | Verdict |
|---|---|---|---|---|
| Sequential fetches in load function | Multiple sequential fetch calls | No | High - waits for each fetch | [X] Bad |
| Parallel fetches with Promise.all | Multiple fetch calls in parallel | Yes | Lower - waits for all fetches together | [OK] Good |