Example of Minification
Let’s take a simple JavaScript code snippet and demonstrate how it can be minified using UglifyJS, one of the popular JavaScript minification tools:
Original JavaScript code:
// Original JavaScript code
function greet(name) {
console.log("Hello, " + name + "!");
}
greet("John");
After minification using UglifyJS:
function greet(e){console.log("Hello, "+e+"!")}greet("John");
The minified version of the code:
- Removes comments.
- Shortens variable names (e instead of name).
- Removes whitespace and line breaks.
- Retains the same functionality as the original code.