Java Reference
In-Depth Information
Minification is the process of removing any unnecessary characters from your code to re-
duce the file size. This includes all comments, whitespace, and other characters that are su-
Tools are available to do this, known as minifiers . Some popular choices include:
YUI Compressor
Google's Closure
These tools can also change variable and function names to single letters. This is often re-
ferred to as code obfuscation as it can make the code more difficult to read. They will also
try to employ optimizations to make the code run faster. For example, here is the Stats mod-
ule that we created earlier in the chapter after it is minified using UglifyJS:
var Stats=function(){function e(e){return e*e}function
eof t==="function"){}return
n e+t})}function n(e){return t(e)/e.length}function
r(r){return t(
As you can see, it is significantly smaller in size, but much more difficult to read and make
sense of!
Minifying your code can have a major effect on the overall size of your files, making them
download and run faster. It also means that your code can use descriptive naming conven-
tions and be well-commented, as these will be stripped away by the minifier tools. As a gen-
eral rule, you should aim to use well-commented and descriptive code in development and
minified code in production (since there is no need for end users to read comments).
Files can also be compressed on the server using a file-compression tool such as gzip, which
can have a dramatic effect reducing the file size. Using both minification and compression
Search WWH ::

Custom Search