Time for action – using UglifyJS
Let's see how you can get a compressed version of the same files you worked on with the Google Closure Compiler:
Open your command-line tool and go to the sample folder created to test the Closure Compiler.
Type the following command in order to concatenate the JavaScript files and to run the UglifyJS2 compressor. For Windows, you can use the
copy
command to concatenate the files:C:\ copy /a *.js index.js $ cat test.js index.js $ uglifyjs --inline-script -o mytest.min.js
Open the generated file and take a look at the source code; you will get the following JavaScript:
var test=function(){var main=function(){alert(“executing manin”);internal()};var internal=function(){alert(“executing internal”)};return{init:main}}();var test=test.init();
Insert the
script
tag in the HTML page and open it in a browser.
What just happened?
You created a compressed version of two simple JavaScript files. As you can see, the output is rather different from the one created with...