开发者

Single letters for naming variables and functions

开发者 https://www.devze.com 2023-02-16 09:16 出处:网络
Context I read a JavaScript code example written by Google. It used: Single lowercase letters for naming variables

Context

I read a JavaScript code example written by Google. It used:

  1. Single lowercase letters for naming variables
  2. Single uppercase letters for naming functions

So the code was illegible.

Questions


Often when large Javascript libraries are put into production the code is "minimized" in order to...

  1. Decrease the download size
  2. 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

0

精彩评论

暂无评论...
验证码 换一张
取 消