DEV Community

Kurapati Mahesh
Kurapati Mahesh

Posted on

Javascript: Minification vs Obfuscation

Minification:

  1. Comments and extra spaces are removed
  2. Provides short names for variables and functions
  3. Removes unwanted variables

Uses:

  1. Reduce file size intern reduces load times
  2. Improves site speed and accessibility
  3. Can be accessed with low bandwidth network

// Sample javascript file
function print() {
console.log('Hello World!');
}
print();

Enter fullscreen mode Exit fullscreen mode

It's minified version is:

function print(){console.log("Hello World!")}print();
Enter fullscreen mode Exit fullscreen mode

Obfuscation:

  1. Business logic is not exposed
  2. Obfuscated isn't readable hence copying and reusing is not possible.
  3. It prevents vulnerable attackes

For the above same code snippet's obfuscated version is:

(function(_0x42a639,_0x56f39){var _0x3177f0=_0x3dc6,_0x3ad656=_0x42a639();while(!![]){try{var _0x39f7cb=-parseInt(_0x3177f0(0x175))/0x1+parseInt(_0x3177f0(0x179))/0x2*(parseInt(_0x3177f0(0x174))/0x3)+-parseInt(_0x3177f0(0x17b))/0x4+parseInt(_0x3177f0(0x176))/0x5+-parseInt(_0x3177f0(0x177))/0x6+-parseInt(_0x3177f0(0x17c))/0x7+parseInt(_0x3177f0(0x173))/0x8;if(_0x39f7cb===_0x56f39)break;else _0x3ad656['push'](_0x3ad656['shift']());}catch(_0x246c48){_0x3ad656['push'](_0x3ad656['shift']());}}}(_0x43bd,0x1c675));function _0x43bd(){var _0x35b3fa=['123SaKLEH','12398znBZem','102425JTqbPj','190338WWUPVw','Hellow\x20World!','1292MJSgQk','log','527404lCUqJG','63973dQqvvq','2035848dPkEIA'];_0x43bd=function(){return _0x35b3fa;};return _0x43bd();}function _0x3dc6(_0xf65f24,_0x5eeff0){var _0x43bdd9=_0x43bd();return _0x3dc6=function(_0x3dc6f1,_0x485198){_0x3dc6f1=_0x3dc6f1-0x173;var _0x3d72ac=_0x43bdd9[_0x3dc6f1];return _0x3d72ac;},_0x3dc6(_0xf65f24,_0x5eeff0);}function print(){var _0xd7f32d=_0x3dc6;console[_0xd7f32d(0x17a)](_0xd7f32d(0x178));}print();
Enter fullscreen mode Exit fullscreen mode

Top comments (0)