DEV Community

Discussion on: 3 JavaScript features that bloat your ES5 bundle

Collapse
 
alexaegis profile image
AlexAegis

What to really do is just don't worry. This is no reason to limit yourself from using certain features.

ES5 only users are a small minority and while supporting them is important, worrying about bundle size for a small fraction of the userbase is unnecessary. Thankfully the nomodule and type="module" script tag attributes come to the rescue.

Just build both and have the ES5 bundle loaded in with the nomodule attribute and the newer one with the type="module" attribute on its script tag. A newer browser will not load the older one and an older one can't load the newer bundle. :)

In Angular 8+ the CLI does this automatically for you by default under the name of "Differential Loading"

Collapse
 
alekseiberezkin profile image
Aleksei Berezkin

It's completely true for applications. I agree that es5 bundle, if exist, must be the separate, and people using recent browsers must not download what they don't need.

However, it's different for libs which provide web runtime — they are still distributed as es5 or even es3 builds. So if you are authoring such a lib you have to keep that in mind and inspect your builds.