Issue link: https://read.uberflip.com/i/1146286
70 | Chapter 10: Rule 10: Minify JavaScript Let's look at what the others could have saved if they had minified. But first, I need to mention a more aggressive alternative to minification: obfuscation. Obfuscation Obfuscation is an alternative optimization that can be applied to source code. Like minification, it removes comments and whitespace, but it also munges the code. As part of munging, function and variable names are converted into smaller strings mak- ing the code more compact, as well as harder to read. This is typically done to make it more difficult to reverse-engineer the code, but munging can help performance because it reduces the code size beyond what is achieved by minification. Assuming that thwarting reverse-engineering is not your objective, the question arises about whether to minify or obfuscate. Minification is a safe, fairly straightfor- ward process. Obfuscation, on the other hand, is more complex. There are three main drawbacks to obfuscating your JavaScript code: Bugs Because obfuscation is more complex, there's a higher probability of introduc- ing errors into the code as a result of the obfuscation process itself. Maintenance Since obfuscators change JavaScript symbols, any symbols that should not be changed (for example, API functions) have to be tagged so that the obfuscator leaves them unaltered. Debugging Obfuscated code is more difficult to read. This makes debugging problems in your production environment more difficult. Although I've never seen problems introduced from minification, I have seen bugs caused by obfuscation. Given the large amount of JavaScript maintained at Yahoo!, my guidelines recommend minification over obfuscation. The ultimate decision has to consider the additional size reductions achieved from obfuscation. In the next section, we'll do some real minifying and obfuscating. The Savings The most popular tool for minifying JavaScript code is JSMin (http://crockford.com/ javascript/jsmin), developed by Douglas Crockford, a fellow Yahoo!. The JSMin source code is available in C, C#, Java, JavaScript, Perl, PHP, Python, and Ruby. The tool of choice is less clear in the area of JavaScript obfuscation. Dojo Compressor (renamed ShrinkSafe and moved to http://dojotoolkit.org/docs/shrinksafe) is the one I've seen used the most. For the purposes of our comparison, I used these two tools.

