fpereiro / gotoB

One .min.js to rule 'em all.
32 stars 2 forks source link

The minified file is bigger than source file #6

Closed beenotung closed 2 years ago

beenotung commented 2 years ago

gotoB.js is 30K in turns of file

Currently, the file size of gotoB.js is 30K, and the file size of gotoB.min.js is 44K, which is bigger than the source file.

If you use the minify cli, you can reduce the file size of gotoB.min.js to 16K.

Setup Steps:

npm i -D minify
npx minify gotoB.js > gotoB.min.js
fpereiro commented 2 years ago

Hi @beenotung ! Thanks for your observation!

gotoB.min.js is already minified. The reason that gotoB.min.js is larger in size than gotoB.js (44k vs 30k) is that gotoB.min.js contains the code for all its dependencies as well. If you added that code, the un-minified file would be 85k.

You can try that by installing the dependencies (by running npm install) and then running node build dev; after you do, you'll see that gotoB.min.js is not minified but does have all its dependencies bundled in it.

The code for building gotoB.min.js is here. In particular, on line 33, we use UglifyJS to minify the file.

Cheers!