🔄 One Slow Call Is Freezing Your Whole Page
A dashboard that loads three widgets, each with its own Ajax call, can end up waiting for the SLOWEST one before showing anything — if those calls are written sequentially with await one after another instead of running in parallel.
🐞 The Problem
async function loadDashboard() {
const sales = await fetch('/api/sales').then(r => r.json()); // 200ms
const inventory = await fetch('/api/inventory').then(r => r.json()); // 2000ms - slow report
const alerts = await fetch('/api/alerts').then(r => r.json()); // 150ms
render(sales, inventory, alerts);
// Total wait: 200 + 2000 + 150 = 2350ms, even though sales
// and alerts were ready in under half a second.
}
🔍 Why This Happens
await pauses execution until that specific call finishes before moving to the next line. Written sequentially, three independent requests run one after another instead of at the same time - the total wait time becomes the SUM of all three, not the time of the slowest one alone.
✅ The Fix: Start All Requests First, Then Await Together
- Promise.all() starts every fetch immediately (they all run concurrently over the network), then waits for all of them together.
- Total wait time becomes the slowest single request, not the sum of all three.
⚡ Correct Version
async function loadDashboard() {
const [sales, inventory, alerts] = await Promise.all([
fetch('/api/sales').then(r => r.json()),
fetch('/api/inventory').then(r => r.json()),
fetch('/api/alerts').then(r => r.json()),
]);
render(sales, inventory, alerts);
// Total wait: ~2000ms (the slowest one) instead of 2350ms
}
⚠️ Even Better: Render What’s Ready, Don’t Wait for Everything
- If the widgets are independent, render each one as soon as ITS OWN request resolves instead of waiting for Promise.all() to finish all three.
- Promise.allSettled() is worth knowing too: unlike Promise.all(), it doesn’t reject everything just because one request fails — useful when a slow widget failing shouldn’t block the fast ones from showing.
Sequential awaits read cleanly top to bottom, which is exactly why they’re easy to write by accident — Promise.all() takes the same three lines of intent and actually runs them the way the page needs.




