There isn't any real distinction between the two. Even UglifyJS calls itself a minification toolkit.
The distinction could be more relevant when comparing JavaScript minification to CSS minification—CSS minification involves only removing whitespace—the original code remains intact.
With JavaScript, 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 it is 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.
Answer from danwellman on Stack OverflowVideos
What is JavaScript Minification?
How does JavaScript Minification work?
Why is Minification used?
There isn't any real distinction between the two. Even UglifyJS calls itself a minification toolkit.
The distinction could be more relevant when comparing JavaScript minification to CSS minification—CSS minification involves only removing whitespace—the original code remains intact.
With JavaScript, 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 it is 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.
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 isn't any 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.
» npm install uglify-js
» npm install @node-minify/uglify-js
The API is minify(code) not minify(file paths)
Copyuglifyjs.minify(fs.readFileSync('geolocation.service.js', 'utf8'))
Copyvar appClientFiles = {
"app" : fs.readFileSync('app_client/app.js', 'utf8'),
"controller": fs.readFileSync('app_client/home/home_controller.js', 'utf8'),
"geolocation": fs.readFileSync('app_client/common/services/geolocation.service.js', 'utf8'),
"data": fs.readFileSync('app_client/common/services/hubRadarData.service.js', 'utf8'),
"filters": fs.readFileSync('app_client/common/filters/formatDistance.filter.js', 'utf8'),
"about": fs.readFileSync('app_client/about/about.controller.js'),
"directives": fs.readFileSync('app_client/common/directives/ratingStars/ratingStars.directive.js', 'utf8'),
}
var uglified = uglifyJs.minify(appClientFiles, {compress: false});
if (uglified.error) throw uglified.error;
This is nice way to minify multiple JS file using uglifyjs remember to always use an object to hold the JavaScript files where the key is the name of the js file and the value is the location of the JavaScript file