PROFESSIONAL-CLOUD-DEVELOPER · Question #66
You are writing a single-page web application with a user-interface that communicates with a third-party API for content using XMLHttpRequest. The data displayed on the UI by the API results is less…
The correct answer is B. Set the asynchronous option for your request to the API to true and omit the widget displaying the. Setting the asynchronous option to true means the XMLHttpRequest runs in the background without blocking the browser's main thread, so the rest of the UI renders normally regardless of API response time. By omitting or hiding the widget that displays the API data when an error…
Question
You are writing a single-page web application with a user-interface that communicates with a third-party API for content using XMLHttpRequest. The data displayed on the UI by the API results is less critical than other data displayed on the same web page, so it is acceptable for some requests to not have the API data displayed in the UI. However, calls made to the API should not delay rendering of other parts of the user interface. You want your application to perform well when the API response is an error or a timeout. What should you do?
Options
- ASet the asynchronous option for your requests to the API to false and omit the widget displaying
- BSet the asynchronous option for your request to the API to true and omit the widget displaying the
- CCatch timeout or error exceptions from the API call and keep trying with exponential backoff until
- DCatch timeout or error exceptions from the API call and display the error response in the UI
How the community answered
(39 responses)- A15% (6)
- B72% (28)
- C10% (4)
- D3% (1)
Explanation
Setting the asynchronous option to true means the XMLHttpRequest runs in the background without blocking the browser's main thread, so the rest of the UI renders normally regardless of API response time. By omitting or hiding the widget that displays the API data when an error or timeout occurs, the application degrades gracefully - the non-critical data is simply absent rather than causing the page to hang or show an error state. Option A uses synchronous (async=false) requests, which block the browser's main thread and freeze the entire UI until the request completes or times out - the worst possible approach. Option C (retrying with exponential backoff) could delay the UI indefinitely and is inappropriate for non-critical data. Option D (displaying the error response in the UI) is acceptable but less clean than simply omitting the widget, and does not address the potential for blocking.
Topics
Community Discussion
No community discussion yet for this question.