Context
I read a JavaScript code example written by Google. It used:
- Single lowercase letters for naming variables
- Single uppercase letters for naming functions
So the code was illegible.
Questions
- Why 开发者_开发知识库this naming?
- What tools are using to do this?
Often when large Javascript libraries are put into production the code is "minimized" in order to...
- Decrease the download size
- Make it more difficult to reverse engineer the code
I think the primary motivator is #1 however.
This process generally involves things like removing comments and whitespace and changing variable references to single characters.
For instance, take a look at JSMin.
Fewer letters means fewer bytes means faster downloads, which is Google's (stated) primary concern.
They probably use Closure Compiler but YUI Compressor is still popular.
That's JavaScript Obfuscation!
Some people do this to obfuscate, but many do it to minify because the fewer characters means that it is a smaller file to transmit.
You can use minification/compression tools and google even has one that is open source:
http://code.google.com/closure/compiler/
It serves two main purposes
- reduced bandwidth, since Google serves so many pages
- obfuscation
http://blogoscoped.com/archive/2008-02-08-n74.html
精彩评论