Home > Enterprise >  Will GSAP animation block the main thread?
Will GSAP animation block the main thread?

Time:10-07

Note that if all the transitions and animations are being applied with CSS, rather than JavaScript, they won't block (or be blocked by) the main thread.

CodePudding user response:

Virtually all JavaScript is executed on the main thread. CSS transitions/animations don't magically avoid that either - only transforms and opacity can be done on another thread, but as soon as your animation involves another property, it's back to the main thread (for all of it, as far as I understand).

A lot of people mistakenly think that CSS transitions/animations are immune from bogging down the main thread, but that simply isn't true. This [old] article may be helpful: https://greensock.com/css-performance/

Beware that there are tradeoffs to having things happen on another thread, like synchronization issues. I'm not saying that's always "bad". Sometimes it doesn't matter. I'm just cautioning against the common mindset of "CSS is always better and never blocks the main thread".

GSAP is highly optimized for performance. In some cases I've even seen it outperform CSS. But to directly answer your question, JavaScript animation will be performed on the main thread.

  • Related