DEV Community

WangLiwen
WangLiwen

Posted on

What are the differences between UglifyJS and JShaman?

What are the differences between UglifyJS and JShaman?

UglifyJS is primarily used for compressing JS code and reducing its size. JShaman, on the other hand, is specifically designed for obfuscating and encrypting JS code, with the aim of making it unreadable, obfuscating functional logic, and encrypting hidden data or characters in the code. It is used for code protection.

Therefore, they are completely different. It is just that UglifyJS also has some obfuscation capabilities, which often leads people to mistakenly believe that it is also an obfuscation and encryption tool.

To demonstrate the difference between the two with an example: Example, file name: example.js, code:

var x = {
    baz_: 0,
    foo_: 1,
    calc: function() {
        return this.foo_ + this.baz_;
    }
};
x.bar_ = 2;
x["baz_"] = 3;console.log(x.calc());
Enter fullscreen mode Exit fullscreen mode

Using UglifyJS for compression, command:

uglifyjs example.js -c -m --mangle-props

-c enables compression
-m enables obfuscation
Enter fullscreen mode Exit fullscreen mode

The result will be:

Image description

var x={o:0,_:1,l:function(){return this._+this.o}};x.t=2,x.o=3,console.log(x.l());
Enter fullscreen mode Exit fullscreen mode

As you can see, UglifyJS removes line breaks, and changes long variable names to short ones, achieving compression without affecting code readability. The functional logic remains clear.

Using JShaman for obfuscation and encryption will result in unreadable and chaotic code.

Image description

Image description

Of course, whether using UglifyJS for compression and obfuscation, or using JShaman for obfuscation and encryption, it will not affect the normal use of the code.

Top comments (0)