Issue link: https://read.uberflip.com/i/1146286
72 | Chapter 10: Rule 10: Minify JavaScript At what point do the additional savings from obfuscation justify the additional risks? Looking at these six examples, I would argue that all of them should simply minify their JavaScript code, thus avoiding the possible problems that obfuscation can cause. The one exception is Amazon, where an additional 17K (9%) would be saved by using obfuscation. A select few properties at Yahoo!, with large JavaScript pay- loads (>100K) obfuscate their JavaScript code. As we'll see below, the delta between minification and obfuscation decreases when combined with gzip compression. Examples To demonstrate the benefits of minification and obfuscation, I have generated two scripts of different sizes: a small script (50K) and a large script (377K). The small script drops to 13K after minification and 12K after obfuscation. The large script is reduced to 129K after minification and 123K after obfuscation. Testing both files under these three states results in the following six examples. Small Script Normal http://stevesouders.com/hpws/js-small-normal.php Small Script Minified http://stevesouders.com/hpws/js-small-minify.php Small Script Obfuscated http://stevesouders.com/hpws/js-small-obfuscate.php Large Script Normal http://stevesouders.com/hpws/js-large-normal.php Large Script Minified http://stevesouders.com/hpws/js-large-minify.php Large Script Obfuscated http://stevesouders.com/hpws/js-large-obfuscate.php Table 10-2. Size reductions from using JSMin and Dojo Compressor Web site Original size JSMin savings Dojo Compressor savings http://www.amazon.com/ 204K 31K (15%) 48K (24%) http://www.aol.com/ 44K 4K (10%) 4K (10%) http://www.cnn.com/ 98K 19K (20%) 24K (25%) http://www.myspace.com/ 88K 23K (27%) 24K (28%) http://www.wikipedia.org/ 42K 14K (34%) 16K (38%) http://www.youtube.com/ 34K 8K (22%) 10K (29%) Average 85K 17K (21%) 21K (25%)

