How can I load several resources and show one page only when they are all ready?
Quick answer
Put the required requests in Promise.all(): it fulfills only when every promise fulfills and rejects if any input rejects. Show a loading state, render the complete page after success, and show an error state if a required request fails. Load optional enhancements separately so they can fail or arrive late without blocking the required page. [S1]
The question, the details, the next step.
A practical checklist
Mark each resource required or optional based on whether the page works without it.
Show a loading state while required data is being fetched.
Use
Promise.all()when every required request must succeed before rendering the page. [S1]Provide a clear failure state and, where appropriate, a retry action.
Handle optional content separately so its failure or delay does not block required content.
Check required success, required failure, and optional failure or delay.
A few more useful answers
When should I use `Promise.allSettled()` instead?
Use it when you need the outcome of every request, including which ones succeeded and failed. It fulfills after all inputs have settled and reports each outcome. [S1]
Does `Promise.all()` give me a loading or error display?
No. It coordinates promise outcomes; your application must show loading before awaiting the requests, render on success, and handle rejection with an error state. [S1]
Should an optional request be included in the required `Promise.all()`?
Not if the page should appear without it. Handle the optional request separately and provide a suitable fallback or update its own area when it succeeds.
Sources
References used for this guide.
- [S1] Promise — JavaScript reference (Microsoft Learn) learn.microsoft.com · Checked
- [S2] Async Programming Patterns for Asynchronous MVVM Applications: Data Binding learn.microsoft.com · Checked
