问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/12768840/minify-and-variable-names