CS Fundamentals Trainer · JavaScript · Performance & Memory

A click handler runs a 400 ms computation on the main thread, which makes the page feel frozen. Which changes let the browser handle input…

A click handler runs a 400 ms computation on the main thread, which makes the page feel frozen. Which changes let the browser handle input and paint while the work is done?

  1. Marking the handler `async` without adding any `await` inside the loop
  2. Splitting the work into chunks and yielding between them with `setTimeout` (or `scheduler.yield()` where supported)
  3. Splitting the work into chunks scheduled with `queueMicrotask`
  4. Moving the computation into a Web Worker and posting the result back
  5. Running the whole computation inside one `requestAnimationFrame` callback

Difficulty: hard

Answer this question

Related questions