The compression of Javascript source codes (a.k.a Minification) is the practice of removing unnecessary characters from the original source code, usually comments, white spaces, line breaks and block delimiters without changing its functionality. Once the code is well minified its file size is reduced improving the download time and thereby reducing the time needed to load it on client and the usage of bandwidth.
Minification is an easy and safe practice and there are several tools that helps you on this task. The most popular are:
- Dojo ShrinkSafe
- Javascript Compressor (also obfuscates)
- YUI Compressor
- JSMin by Douglas CrockFord
Obfuscation is a similar technique which besides code reduction also changes the functions and variables names making the code harder to read and making the reverse engineer more difficult (not impossible though), however the use of this technique is more likely to generate bugs and make the code harder to debug, so use it carefully.
The Javascript Compressor online tool has an optional obfuscation parameter which besides minification also obfuscate the source code with 3 different encodings.