Java Reference
In-Depth Information
Minification
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-
perfluous.
Tools are available to do this, known as minifiers . Some popular choices include:
YUI Compressor
Google's Closure
UglifyJS
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
t(e,t){if(typ
eof t==="function"){e=e.map(t)}return
e.reduce(function(e,t){retur
n e+t})}function n(e){return t(e)/e.length}function
r(r){return t(
r,e)/r.length-e(n(r))}return{mean:n,standardDeviation:r}}()
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