JavaScript Interview Question #162
What is minification?
Performance, Browser APIs, Rendering & Modern Web Architecture Senior Advanced
Quick Interview Answer
Minification reduces JavaScript file size by removing unnecessary whitespace and comments and by applying safe code transformations such as shortening local identifiers where appropriate.
Detailed Explanation
Minification reduces JavaScript file size by removing unnecessary whitespace and comments and by applying safe code transformations such as shortening local identifiers where appropriate.
Minification improves transfer size but does not replace compression such as Brotli or gzip. Production build systems commonly combine minification with compression, caching, code splitting, and source maps.
Code Example
// Development:
function calculateTotal(price, quantity) {
return price * quantity;
}
// A minifier may produce something conceptually like:
function calculateTotal(t,n){return t*n}