Book Image

PhoneGap Beginners Guide (third edition)

Book Image

PhoneGap Beginners Guide (third edition)

Overview of this book

Table of Contents (22 chapters)
PhoneGap Beginner's Guide Third Edition
Credits
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Related Plugin Resources
Index

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:

  1. Open your command-line tool and go to the sample folder created to test the Closure Compiler.

  2. 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
    
  3. 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();
  4. 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...