I am using UglifyJS 2 to concatenate and minify a bunch of JavaScript files (not too much, around 5 to 10). This process is run from within Node.js by using the default settings of UglifyJS 2.
The files are basically Require.js, jQuery, Backbone.js, Backbone.js Marionette, Moment.js, and some additional (smaller) helper files, all in the uncompressed (i.e. development) versions.
The problem is that this process nearly takes 10 seconds.
If I disable minification completely by handing over
{ compress: false }
as an option, it's a lot faster, but it still takes around 2 seconds.
Question #1: Is it usual that UglifyJS 2 takes that long even for a few files? Or am I most probably doing something wrong?
Question #2: How can I speed up this process, without disabling all the useful options of UglifyJS 2?
If you set the compress unused option to false, it should speed it up a bit. I got mine from 11sec to 5.5sec with just that.
{
compress: {
unused: false
}
}
Less than a 2k difference with it off.
It's not uncommon that minifiers take a few seconds to compress multiple large files. 8-12 seconds is okay in your case (multiple large libraries).
However, I recommend not to compress these libraries yourself. Most of them have a team of developers behind them who really know what they're doing, I recommend downloading the minified versions from the source and do as simple as
copy *.min.js allLibraries.js
or
cp *.min.js allLibraries.js
Note: Make sure you concatenate in the correct order, this usually means The main libraries -> The plugins -> Your code
.
As for speeding up, other than disabling the cool features like the strong compression, there's nothing much you can do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With