After JavaScript is baked it is time to think about fastest delivery of your fresh tasty product. You might think about how to shrink your source to minimize download time. There are couple ways to achieve this goal by using minification and compression. Don't think about them as the different names for the same process they are different and can be combined to get better result.
Minification is the process of eliminating unnecessary characters from java script that doesn't affect functionality like white-spaces, comments and shorten the names of script objects. The resulting file stays in the same text format and can be opened and read by regular text editor.
Compression is the process of shrinking JavaScript text even further using special compression algorithm. Resulting file is not readable and must be decompressed to be used. Modern browsers understands files received with header 'Content-Encoding: gzip' and decompress them by default.
To get best results files with JavaScript could be minified and then compressed.
There are several popular minifiers out there:
Minification is the process of eliminating unnecessary characters from java script that doesn't affect functionality like white-spaces, comments and shorten the names of script objects. The resulting file stays in the same text format and can be opened and read by regular text editor.
Compression is the process of shrinking JavaScript text even further using special compression algorithm. Resulting file is not readable and must be decompressed to be used. Modern browsers understands files received with header 'Content-Encoding: gzip' and decompress them by default.
To get best results files with JavaScript could be minified and then compressed.
There are several popular minifiers out there:
- YUI Compressor
- Cosure Compiles
- UglifyJS
It is definitely worth to automate minification process and do it during the packaging of your application. Whatever you use in your build and CI there is always some sort of build extensions that can do it for you.