-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bundle Size] lottie-web is 237.5kB minified— could this be improved? #1184
Comments
You can use the light version that only supports the svg renderer and no expressions. |
For reference, lottie_light is 144kB minified and 38.5kB minified + gzipped. I pulled it from https://unpkg.com/lottie-web@5.2.0/build/player/lottie_light.min.js to check the filesize. Considering the light version is half the size, are there additional improvements that could be made to make the light version lighter? |
Thank you guys for this information! |
Not sure light is a fair name when it's nearly 40kb. Should it be called lottie and lottie-full? |
This + the actual size of lottie files is are a pretty limiting constraint. I'm not quite sure this has been optimized for the web, where the first paint depends heavily on the initial js bundle size. On mobile it doesn't matter since it's only experienced at install time, but on web this is critical |
Unfortunately, trying to squeeze a good chunk of After Effects into anything smaller than 60Kb is not an easy task :) |
Is there a way to get the svg only lottie light through npm? Currently the docs recommend:
Could there an option for:
|
@aidanlister , you should be able to import it doing |
How does one define which player to use when its used as part of a build? I know when its specified in html its in the script tag but how do I get it to specifically use lottie_light.js as part of a build? for example, currently its being called like this:
does this mean its calling the lottie.js player? For lottie light would it be like this?
or DOES it have to be specified as a the path as mentioned above: |
Does anyone know what @bodymovin meant by 'expressions'? |
@seb-thomas they are referring to After Effect expression. In AE, you can put JS Code into animated properties. So, if the person who generated the JSON file used expression for that file, it wouldn't work. |
this is docs worthy |
I don't really agree, because coding them by hand would not have the overhead of Lottie / Lottie light. So it's not a 1:1 comparison. Lottie animations will almost always require more resources and size.
Are there metrics that prove that? Also, it's probably easier to "load on demand" for video files, since Lottie assets end up being bundled in JS bundles, and most people do not use code splitting correctly. A video file, in contrast, is a small file which only gets downloaded when requested on a particular page, and can being playing before its fully loaded. So I wonder, in real-world usage, if Lottie ends up taking up more time to interactive. |
Hello, same here, lottie is the biggest lib in our node_modules, I just checked if there is a way to optimize that, and we found the min, I will have a try, but we use json lottie file, will it work with the min version? Otherwise, do we need all the lottie player ? we only use json anims. Note: we use lottie-web through another module called react-native-web-lottie and we don't handle the import directly in our source code, see issue here, do you think it is possible to use the light version in here? Edit: we can |
In order to verify the improvements, I've modified locally the size-stats example and used bundle analizer to compare the results. 1. Used an online tool to compress the lottie JSON files for Vivo-new logo. This improved in 20% the total size of the lotties: - Before:  - After:  2. I noticed that the main bottleneck was using `lottie-react` to render the lotties. This lib imports `lottie-web`, and that library is quiet heavy. [Some people recommended](airbnb/lottie-web#1184 (comment)) importing `lottie-light` from `lottie-web` and using it as replacement for the default one. What I've done is copying a minimized version of ([lottie-react](https://github.com/Gamote/lottie-react/blob/main/src/components/Lottie.ts) into our repository and adapted it to use `lottie-light` instead of `lottie-web`. This caused a pretty big improvement (over 50% of the total size of the lib). - Before:  - After:  In total, by using the exact same example in size-stats, we can see that the bundles size has been reduced by over 160kb: - Before:  - After:  ## 🗒️ Note The size stats comment in this PR only shows the improvements caused by compressing the vivo lotties. The ones obtained by replacing the lottie library are not visible because the example page in the size-stats doesn't use a BrandLoadingScreen component (and the lotties are imported lazily). Refer to the images I've attached in this description to see the impact.
# [16.1.0](v16.0.0...v16.1.0) (2024-09-27) ### Features * **BrandLoadingScreen:** improve lottie animations ([#1235](#1235)) ([e7dc87f](e7dc87f)), closes [/github.com/airbnb/lottie-web/issues/1184#issuecomment-411586909](https://github.com//github.com/airbnb/lottie-web/issues/1184/issues/issuecomment-411586909) * **Form fields:** allow blocking copy/cut ([#1251](#1251)) ([8fd2838](8fd2838)) * **Form fields:** improve accesibility of errors ([#1246](#1246)) ([e35a99e](e35a99e)) * **PhoneNumberField:** Custom formatter support + lazy load libphonenumber on demand ([#1244](#1244)) ([2ee88e9](2ee88e9)) * **PosterCard, DisplayMediaCard:** allow using srcSet for backgroundImage ([#1253](#1253)) ([3b3d85f](3b3d85f)) * **Rating, InfoRating:** new components ([#1196](#1196)) ([02c91f6](02c91f6)) * **SearchField, TextField:** support inputMode prop ([#1249](#1249)) ([fe31eca](fe31eca)) * **Sheet:** lazy load sheet implementations ([#1250](#1250)) ([40fecdd](40fecdd))
According to Bundlephobia, lottie-web@5.2.0 is 237.5kB minified, and 60.5kB minified + gzipped.
Are there any potential optimizations that could be made? I'm interested in adopting Lottie, but it has a fairly substantial footprint.
The text was updated successfully, but these errors were encountered: