Performance: Parallel data loading
This concept affects how fast the page can start rendering by loading multiple data sources at the same time.
export async function loader() { const [user, posts] = await Promise.all([fetchUser(), fetchPosts()]); return { user, posts }; }
export async function loader() { const user = await fetchUser(); const posts = await fetchPosts(); return { user, posts }; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Sequential data loading | Minimal | 1 per data update | High due to delayed paint | [X] Bad |
| Parallel data loading | Minimal | 1 after all data ready | Lower due to faster paint | [OK] Good |
data?
export async function loader() {
const userPromise = fetch('/api/user').then(res => res.json());
const postsPromise = fetch('/api/posts').then(res => res.json());
const [user, posts] = await Promise.all([userPromise, postsPromise]);
return { user, posts };
}export async function loader() {
const user = await fetch('/api/user').then(res => res.json());
const posts = await fetch('/api/posts').then(res => res.json());
return { user, posts };
}Pass the test and this pattern moves unknown