Search code examples
javascriptcoding-style

using uglyfyjs 3 output file same as original


I have some simple JavaScript file named test.js the file contain the following code:

function foo(){
    console.log('hi');
}

Since all client code is exposed to the client, I am trying to 'hide' it or to make it unreadable.

I downloaded uglify-js, I tried to run the command

uglifyjs test.js --output test.min.js

Then the output file contains the following:

function foo(){console.log("hi")}

i.e almost the same code, readable code

Am I missing something?


Solution

  • Your function foo is defined in the global scope, so its name can't be obfuscated/minified. Changing it might break other codes that were calling this function.

    All other words are either keywords (function), built in objects (console), object methods (.log) or string literals ('hi'). These can't be changed without breaking your code.

    So, all in all, there is no changes because nothing can be changed.