omega
omega

Reputation: 43963

How to compress files as much as possible in JS Uglify2?

I am new to js uglify 2 https://github.com/mishoo/UglifyJS2 and I am trying to figure out how to compress a bunch of js files as much as possible, but not have anything break. So far I have this:

var result = uglifyJS.minify([ 
    "A.js", "B.js"
], {
    mangle :true,
    compress: {
        sequences: true,
        properties: true,
        dead_code: true,
        drop_debugger: true,
        conditionals :true,
        evaluate :true,
        booleans :true,
        loops:true,
        unused:true,
        hoist_funs: true,
        if_return:true,
        join_vars:true,
        cascade :true,
        collapse_vars :true,
        global_defs: {
            DEBUG: false
        }
    }
});

Does anyone know if this is right, and what else I can change/add?

Also for properties option, it apparently changes things like a["b"] into a.b, but what if I had a[" s"] would it change it into a. s? Because that would break it.

Thanks

Upvotes: 0

Views: 456

Answers (1)

compressorator
compressorator

Reputation: 11

To get better compression still add these additional compress options:

    pure_getters: true,
    unsafe_comps: true,
    screw_ie8: true,

and this option is generally safe for most code:

    unsafe: true,

Uglify won't transform a[" s"] into a. s.

Upvotes: 1

Related Questions