
Answer-first summary for fast verification
Answer: Set the asynchronous option for your request to the API to true and omit the widget displaying the API results when a timeout or error is encountered.
The key requirements are that API calls should not delay UI rendering and it's acceptable to omit the API data on errors. - **Option A** uses synchronous requests (`asynchronous: false`), which block the UI thread, delaying rendering. This violates the requirement to avoid delaying other parts of the UI. - **Option B** uses asynchronous requests (`asynchronous: true`), allowing non-blocking UI rendering. Omitting the widget on errors aligns with the requirement to tolerate missing API data. - **Option C** implements retries with exponential backoff, which is unnecessary since the API data is non-critical and errors are acceptable. - **Option D** displays errors in the UI, which contradicts the instruction to omit the widget entirely on failures. Thus, **B** is the correct choice as it satisfies both non-blocking UI and graceful handling of API failures.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
How should you design a single-page web application where the UI communicates with a third-party API via XMLHttpRequest, ensuring that non-critical API data doesn't block UI rendering, while maintaining good performance during API errors or timeouts?
A
Set the asynchronous option for your requests to the API to false and omit the widget displaying the API results when a timeout or error is encountered.
B
Set the asynchronous option for your request to the API to true and omit the widget displaying the API results when a timeout or error is encountered.
C
Catch timeout or error exceptions from the API call and keep trying with exponential backoff until the API response is successful.
D
Catch timeout or error exceptions from the API call and display the error response in the UI widget.
No comments yet.