question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[feature request] Make it possible to initialize a lottie instance without giving a reference to a DOM node

See original GitHub issue

Sometimes it takes very long for the animations to load. While the animations are being loaded the main thread is blocked by Lottie for a significant amount of time - even hundreds of milliseconds on Core i7 CPU.

I was trying to offload Lottie initialization to a Web Worker - I wanted to call lottie.loadAnimation from within a Web Worker thread. But it turned out It is not possible because WebWorkers don’t have access to DOM while lottie.loadAnimation method requires a reference to a DOM node to be passed as the container argument.

So I wonder is it possible to make the loadAnimation method DOM agnostic? It would be great if we could initialize the Lottie instance in a Web Worker thread, return it, and then mount on a DOM element.


PS I know there’s a canvas rendered, but Offscreen Canvas, which is supported by WebWorkers has still very poor browsers’ support: https://caniuse.com/#feat=offscreencanvas

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:24

github_iconTop GitHub Comments

12reactions
wujekbogdancommented, May 9, 2020

I’ve described the reason in my first post in this topic: https://github.com/airbnb/lottie-web/issues/1860#issue-521131207


Lottie initialization process is a very CPU-heavy process, in case of complex animations the main thread gets busy for hundreds of milliseconds, even up to a 1s and more (depending on the animation complexity and the CPU). JS is single-threaded, because of this, while the animation is being processed by lottie-web, the whole application’s UI is frozen (all the animations are stopped, hovers don’t work, events are being triggered, etc). It gives a very bad user experience.

WebWorkers run in a separate thread, so offloading the init process to a separate WebWorker thread would make the init process way smoother.

So basically, this is a very standard use case for WebWorkers.

4reactions
mustafaabobakrcommented, Apr 21, 2022

Any updates ? How to init Lottie in a web worker Nextjs?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced Interactions - Lottie Docs - GitHub Pages
Advanced Interactions. This page will describe how to create lotties with advanced interactivity, specifically when used with lottie-web player.
Read more >
Lottie Player - Interactivity Guide - LottieFiles
This is a quick demo for using the Lottie interactivity library with the Lottie Web Player component and the Lottie Player to add...
Read more >
Lottie Docs
Lottie is a library for Android, iOS, Web, and Windows that parses Adobe After Effects animations exported as json with Bodymovin and renders...
Read more >
Top 5 lottie-web Code Examples - Snyk
json`); lottie.loadAnimation({ container: container.current, // the dom element that will contain the animation renderer: 'svg' ...
Read more >
APP_INITIALIZER - Angular
You can, for example, create a factory function that loads language data or an external configuration, and provide that function to the APP_INITIALIZER...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found