I know that minification is responsible for removing: white space characters, new line characters, comments, and sometimes block delimiters. Not long ago I read it's also responsible for shorten variable names. But I always thought it's a part of obfuscation. Am I right? Or now minification libraries also include such functionality?
The answer to your question in most cases of minification is: Yes, most minifiers will randomly rename variable/function/etc. names, starting with single letters, if needed extend to 2-letters, and continuing to avoid long names.
Minification is the process of minimizing code and markup in your web pages and script files. It's one of the main methods used to reduce load times and bandwidth usage on websites. Minification dramatically improves site speed and accessibility, directly translating into a better user experience.
Minification is just removing unnecesary whitespace and redundant / optional tokens like curlys and semicolons, and can be reversed by using a linter. Uglification is the act of transforming the code into an "unreadable" form, that is, renaming variables/functions to hide the original intent...
It is important to minify your CSS and minimise JavaScript files so they can load faster on your web pages. There are many reasons why you should minify your CSS and JavaScript: Reduce file size: The more code there is in a file, the larger it will be. Minified code is usually much smaller than the original version.
Well, since the objective of minification is to reduce the size of the code as much as possible, renaming variables is an effective way of doing just that.
A trick that JavaScript minifiers often use, is to wrap the code in a immediately executed function, with a lot of arguments:
(function(a,b,c,d,e,f,g){/* ... */})();
This makes it possible to use these variables without declaring them with the var
keyword, thus reducing the size of your code by three bytes times the number of var
keywords.
Modern minifiers use a lot of these advanced tricks to reduce the size of your code, that the code seems obfuscated is just a bi-product of the minification.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With