Search code examples
javascriptrequestanimationframe

Does requestAnimationFrame can be stuck by long javascript


I know the requestAnimationFrame be invoked before the re-rendering of the browser, and the frequency is about 60fps, but if there is a very long javascript in the callback of requestAnimationFrame does it can block the re-rendering of the Browser? and therefore stuck the next requestAnimationFrame?

And move over, Why the browser re-rendering in 60fps, if there no content or style changed?


Solution

  • Yes.

    As with any event-based function call (requestAnimationFrame, setTimeout, addEventListener, etc.) if the JS engine is busy running another function (even the same function from an earlier iteration) then the new function can't run until the previous one is finished.