Reputation: 9426
I have a JavaScript file that I ran through the Google Closure compiler, and it munged the name on
to za
, which is obviously not more efficient from a length standpoint. Is there some reason it is, in fact, more efficient (possibly because of the letters used), or is it just a couple random letters?
For instance, I can imagine that za
might be more compressible than on
when Gzipped, but there's a good chance it's just a couple of random letters.
Upvotes: 0
Views: 261
Reputation: 18023
After playing around with http://closure-compiler.appspot.com/home some, it seems that the compiler just start renaming the variable regardless of their previous name. It stays at 'a' and makes it way through 'b', etc... It does not appear to care about current length of the variable name, but it will make sure the overall size is the same or smaller than before. In some cases variable may be refactored out of the code if you use the advanced optimization setting.
By letting the compiler handle the naming of your variables it is sure that none of them conflict with each other. If it tried to keep your existing variable name it would have to keep track of that separately and maintain a list to compare against.
Another benefit of minifying code is to obfuscate your code base. Sure someone can figure it out if they really wanted to, but by making the variable names programatic it makes it harder to figure out the meaning.
If you really wanted to debug through combined & minified code I would recommend looking into the source maps feature of Google Chrome Canary http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/
Upvotes: 3
Reputation: 359776
Is there some reason it is, in fact, more efficient (possibly because of the letters used)
No.
or is it just a couple random letters?
Pretty much. AFAIK, Closure Compiler (and other JS minifiers) systematically renames variables, with the goal of using fewer characters overall, without looking at what they are already named.
Upvotes: 1