How to speed up the minification process of UglifyJS 2?

Golo Roden picture Golo Roden · Mar 16, 2013 · Viewed 9.3k times · Source

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?

Answer

phazei picture phazei · Nov 20, 2015

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.