Browser & Web Performance · Middle · Question 11 of 75
A click handler does heavy, non-urgent work after updating the UI. How can you make the update appear sooner?
button.addEventListener("click", async () => {
showSpinner();
// ...heavy work here
});- ✓Correct answer: Yield to the main thread after the UI update (e.g.
await scheduler.yield()), then do the heavy work - 2Move
showSpinner()to the end of the handler - 3Wrap the heavy work in
try/finally
Explanation
Yielding lets the browser paint the spinner before continuing. Without it, the frame waits for the whole handler.