Browser library bundle size is very large.
See original GitHub issueHi! While looking into using Datadog RUM, I noticed the bundle size is much bigger than I’d expect: @datadog/browser-rum bundle analysis. Currently it’s about half the size of our entire UI component library, including styles.
Most of this comes from @datadog/browser-core and its dependencies.
While there’s a lot of code in the packages themselves, the size is mostly inefficiency in dependencies and bundling. This is good! It’s the easiest to cut down.
Likely highest gains:
- Inline
merge
andassign
functions in the project instead of usinglodash
. The two lodash imports account for almost 25% of the total size. - Consider switching from
tsc
to rollup, possibly using tsdx to save headaches. Rollup is specifically designed for building self-contained libraries, and will avoid thetslib
dependency (the second largest afterlodash
).
Issue Analytics
- State:
- Created 3 years ago
- Reactions:27
- Comments:17 (2 by maintainers)
Top Results From Across the Web
Small Bundles, Fast Pages: What To Do With Too Much ...
This post will explain why bundle size matters and recommend tools and ... Large amounts of JavaScript negatively affect site speed in two ......
Read more >Slimming down your bundle size - LogRocket Blog
Bundle optimization #2: Install lighter-weight alternative libraries. React's bundle size is still a bit large (124KB in our project), even ...
Read more >Optimizing JavaScript bundle size - DebugBear
It's easy to keep adding new packages and lose track of the size of your Webpack, Parcel, or Rollup bundle. But large JavaScript...
Read more >5 Methods to Reduce JavaScript Bundle Size - Bits and Pieces
Today, we use JavaScript heavily in web development, and we can find many applications with large bundle sizes. However, beyond a certain ...
Read more >How CommonJS is making your bundles larger - web.dev
CommonJS modules are very dynamic, which prevents JavaScript ... bundle size is still the number one reason for making browser apps slower.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@fdc-viktor-luft We did consider creating a package supporting only ES6 syntax. It didn’t yield significant-enough results to justify maintaining such package right now. Because IE11 will be retired in june, we will reconsider it and may drop IE11 altogether.
We just realized an audit of our SDK bundled size. Here are the main efforts that we will work in the coming weeks/months:
#1335 Drop old browsers support when computing stack traces. While the SDK support only IE11 and newer browsers, we still have some code to support very old browsers when computing stack traces. Let’s remove it.
#1354 Tweak build-env setup to improve dead code removal. We currently have build flags to produce slightly different bundles for tests. This setups could be improve to allow more dead code removal in release bundles.
#1364 Use const enum when possible. We currently have large TS enums that are used accross the SDK, using const enums would help to reduce the bundle size.
#1347 Remove TSLib usage. We barely use it and could cause a big size overhead if it’s not tree-shaken (depending on NPM users build setup)
Avoid using
class
syntax. This syntax is hard to mangle, especially when transpiled to ES3Avoid using optional chaining and nullish coalescing operators, which often produce more code than expected when transpiled.
Other notes:
we experimented using another bundler (ex: rollup), and it didn’t have a significant impact size-wize. We are using a custom ESLint rule to ensure that most of our codebase is side-effect free and can be tress-shaken by terser almost as well.
we are considering using code-splitting, so various parts of the SDK could be loaded only if needed. This would be a breaking change, so not actionable right now, but definitely something to keep in mind when the occasion presents itself.