Minifying, or minification, is where you put off useless characters out of your code, whether or not they is probably whitespace (inclusive of indentation), code that isn't ever used, feedback for your code, or lengthy names for variables that may be changed with something shorter.
Minification of your code effects in it taking up much less area, making it faster to ship from a server to a patron, as well as using less bandwidth in doing so. This improves the consumer's enjoyment of your web page as it could load faster.
You ought to best minify the code that you are distributing though, now not your supply version which you are writing, as minified code is tougher to read and recognize, making debugging greater complex. Providing a source map facilitates this, because it maps the minified code returned to the source code, permitting manufacturing mistakes to be mapped to the appropriate little bit of code in the source version.
There are numerous unique options available for minifying your code in a production workflow, including uglify-js or minify, however, Terser seems to be the maximum popular device presently to be had, as it can cope with each ES5 & ES6 syntax out of the box.
Terser is available on NPM and may be mounted to your mission with npm set up terser. Optionally, you can install it globally on your gadget by adding the -g flag to the command, permitting the CLI for use anywhere and the module to be covered in any challenge.
Many developers will keep a 'pretty' model, and upon deployment in their project run their scripts thru a minification application.
The reason for minification is to increase the rate of a website. Minimization can make a script up to twenty% smaller, resulting in a quicker download time. Some developers will even use it to 'obfuscate' their code. This makes it difficult for the code to be examined, thereby making it tougher to oppose engineer or copy.