JavaScript Minification
The process of removing all unnecessary characters from JavaScript source code without affecting its functionality is known as a Minification.
Minified cannot be written during development since the developer must debug and understand the code. If minified code is written while developing, other developers will find it difficult to understand and debug the flow.
The minified process will remove extra spaces, comments, and variables from the code, resulting in a smaller js file. Please note that minification does not mean compression. compression reduces the bits to file size.
The main benefit of a minified procedure is that it improves site performance and reduces page load time.
Get Pritey Mehta’s stories in your inbox
Join Medium for free to get updates from this writer.
Minification is strongly recommended for production deployment; follow these steps to minify the js file.
If your project does not have a package.json file or any JS framework projects, then create package.json file and then run:npm install terser
it adds the terser package to your project, which helps to minify the JS code. find out more about terser
Now, to minify the sample.js file, just run this command: npx terser -c -m -o sample.min.js -- sample.js
it will generate the sample.min.js file as minified js file.
here you go !






