Google Cloud Professional Cloud Developer — Question 4

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?

Answer options

Correct answer: B

Explanation

The correct answer is B because setting the asynchronous option to true allows other parts of the user interface to render without waiting for the API response, which improves performance. Option A is incorrect as it would block rendering, leading to a poor user experience. Options C and D do not align with the requirement to avoid delays in rendering, as they focus on handling errors rather than optimizing the user interface's performance during API calls.