DEV Community

Cover image for I reduced an npm package size by 50% with minification

I reduced an npm package size by 50% with minification

Caleb O. on September 27, 2022

Web performance is something that a lot of people do not consider when they set out to build software that works on the web. Everyone should stri...
Collapse
 
jonrandy profile image
Jon Randy 🎖️ • Edited

Import packages via Skypack and you can get minified versions regardless of whether the original package was minified

Collapse
 
seven profile image
Caleb O.

Gone through the basics of the docs

But, wait... if one is fetching or importing data from a CDN. Doesn't that increase the issue of poor load times for folks with a very poor bandwidth?

Collapse
 
dagnelies profile image
Arnaud Dagnelies

Well, the whole purpose of a CDN is to make things load faster. Your statement / question is quite confusing.... And loading a minimized version of anything looks like pretty useful to me.

Thread Thread
 
jonrandy profile image
Jon Randy 🎖️ • Edited

I think maybe he was getting at the bundler question. This is the area where the debate is for me. It's arguable that if some of your dependencies rarely change, then it may be better leaving them out of the bundle and loading them externally from a CDN. This will reduce your bundle size, and all these unchanging dependencies will be cached locally (+ fast loading initially). I believe there are plugins lying around that can make specified dependencies use Skypack in production builds.

Thread Thread
 
seven profile image
Caleb O.

Great! Thank you for pointing this out too. 🚀

Thread Thread
 
seven profile image
Caleb O.

Just to be clear again...

It'll be better to do something like

import React from "skypack/link/that/points-to-the-react-package" 
Enter fullscreen mode Exit fullscreen mode

Instead of the normal way. Yeah?

@jonrandy

Thread Thread
 
dagnelies profile image
Arnaud Dagnelies • Edited

It depends. If you pull a library "from the browser", it is preferable to be minified. If you pull a library "in your npm project", the sources are often preferable, since the whole app is bundled/minified in the end anyway.

Thread Thread
 
seven profile image
Caleb O.

Now, this is clear.

Thank you! 🍷

Collapse
 
jonrandy profile image
Jon Randy 🎖️

That's a whole different subject and debate

Thread Thread
 
seven profile image
Caleb O.

Do you mind walking me through it?

Collapse
 
dagnelies profile image
Arnaud Dagnelies

That Skypack is a very interesting thing, I will try it out some day.

Collapse
 
dagnelies profile image
Arnaud Dagnelies

For bundling/minification, you might also be interested to take a look at esbuild

Collapse
 
seven profile image
Caleb O.

Great! I'll check this out too.