Does it make sense to do both minify and uglify?
Asked Answered
L

3

21

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?

Lynching answered 14/11, 2015 at 12:3 Comment(5)
Possible duplicate of grunt - what's the difference between concat and uglify and minifyCourser
That question doesn't answer my question. Doesn't explain whether it makes sense to do both.Lynching
There is an answer saying that: minifying just is removing unnecesary whitespace and redundant / optional tokens like curlys and semicolons, and can be reversed by using a linter uglification is the act of transforming the code into an "unreadable" form, that is, renaming variables/functions to hide the original intent... it is also un-reversable. which means that they are two different thingsCourser
I looked at npmjs.com/package/gulp-uglify It seems to say uglify involves minifying a file. Hence, I'm confused.Lynching
Gulp: Build system automating tasks: minification and copying of all JavaScript files, static images.. it is a built system which also minify's, it is not uglification uses minificationCourser
A
33

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.

Afterthought answered 14/11, 2015 at 12:20 Comment(0)
C
21

Minifying is just removing unnecessary white-space and redundant like comments and semicolons. And it can be reversed back when needed.

Uglifying is transforming the code into an "unreadable" form by changing variable names, function names, etc, to hide the original content. Once it is used there's no way to reverse it back.

Some libraries like UglifyJS does minification when used, by removing unnecessary parts. But in general Uglifying is making the code unreadable.

Minifying your code speeds up your page loading, making visitors and search engines happy and it is also readable. Most major browsers minify the code before execution.

Courser answered 14/11, 2015 at 12:36 Comment(2)
So should we Uglify the JS so that its not copied by anyone? Whats the real purpose of Uglification?Grannia
@AdityaBokade It can be copied by someone, but it won't be in a readable format. Like for instance variable or function names become single letters... So, understanding the real purpose of anything declared will get very complicated. If the JS file size is too big, it's nearly impossible to understand it unless the entire code is re-written.Courser
J
0

Uglifying and minifying JS code makes loading pages a little faster and makes code less readable but not unreadable. Like someone just said, we should not confuse uglifying and minifying for encryption.

Joyous answered 28/2, 2023 at 6:17 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Clareclarence

© 2022 - 2024 — McMap. All rights reserved.