javascriptobfuscationminifyuglifyjs

Does it make sense to do both minify and uglify?


Given that uglification involves some minification in the process, does it still make sense to do both minify and uglify? If yes, should one minify or uglify first? Is it enough to do uglify only? Will the code be more obfuscated if both are done?


Solution

  • There is no real distinction between the two. Even Uglify calls itself a minification toolkit.

    The distinction could be more relevant when comparing JS minification to CSS minification - CSS minification involves only removing whitespace - the original code remains intact.

    With JS it is possible to not only remove whitespace, but also to make transformations to the code, such as truncating variable names to single characters.

    Minifying JavaScript not only makes the source smaller, it also makes the code less readable, or obfuscates it. But do not operate under the assumption that minification or uglification, or whatever you want to call it, is a security measure. It isn't encryption. The code is harder to read, but not impossible to read, and while it's not usually possible to return minified code back to its original form, it is possible to 'beautify' it and make it more readable.

    It doesn't make sense to both minify and uglify because most minifiers will both remove whitespace and unnecessary characters, as well as obfuscate the code. All you're doing is introducing another build step.