Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't jQuery use requestAnimationFrame?

Some browsers support requestAnimationFrame, so why not use it? After all, it's been supported since Google Chrome 10. Despite that, jQuery does not seem to be using it. I've found a bug report about it, but no real explanation was given? I'm sure the jQuery people have their reasons, though.

Why wouldn't they use this awesome API?

like image 615
Randomblue Avatar asked Nov 03 '11 17:11

Randomblue


People also ask

Is requestAnimationFrame better than setInterval?

requestAnimationFrame is a bit trickier to get working then setInterval , but it is so much more performant and accurate that the small amount of extra effort is worth it.

Why should I use requestAnimationFrame?

To optimize system and browser resources, it is recommended to use requestAnimationFrame , which requests the browser to execute the code during the next repaint cycle. This allows the system to optimize resources and frame-rate to reduce unnecessary reflow/repaint calls.

Is requestAnimationFrame asynchronous?

As now you know that the rAF is a Web API, that means the callback will be called asynchronously. Unlike setInterval , requestAnimationFrame does not accept delay argument, instead, it only calls the callback function when the browser is ready to perform the next paint operation.

Does react use requestAnimationFrame?

React doesn't currently use requestAnimationFrame to do DOM updates (as we call it, the "batching strategy"). The batching strategy is injectible though so it's possible to use something else.


1 Answers

In ticket #9381 you can read why they stopped using requestionAnimationFrame after some time.

To summarize, problems were that animations didn't run (browsers try to reduce CPU load) when window didn't have focus, which is OK if the window is hidden, but not if it is visible, just out of the focus. Furthermore, animation queues piled up and after window regained focus, things went berserk. This would require ugly changes in the code and/or changes how people add things to the animation queue. So it was decided that support is removed until there is some better way to do this.

like image 124
Mitar Avatar answered Oct 11 '22 16:10

Mitar