Performance: Layout load functions
MEDIUM IMPACT
Layout load functions affect the initial page load speed and data fetching timing, impacting how fast the main content appears.
export async function load() { const [res1, res2] = await Promise.all([ fetch('/api/data1'), fetch('/api/data2') ]); const data1 = await res1.json(); const data2 = await res2.json(); return { data1, data2 }; }
export async function load() { const res1 = await fetch('/api/data1'); const data1 = await res1.json(); const res2 = await fetch('/api/data2'); const data2 = await res2.json(); return { data1, data2 }; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Sequential fetch in load | Minimal | 0 | Blocks paint until data arrives | [X] Bad |
| Parallel fetch with Promise.all | Minimal | 0 | Faster paint due to quicker data availability | [OK] Good |
| Heavy CPU work in load | Minimal | 0 | Blocks main thread delaying paint and interaction | [X] Bad |
| Light load function, heavy work deferred | Minimal | 0 | Non-blocking paint and interaction | [OK] Good |