8 March 2016

This snippet shows how to minify javascript files from command line. Minifying JavaScript is useful in many respects. Most important are security and performance. Security is increased due to the fact that minified javascript is harder to read, minification renames your variables to shorter ones and that can hide some business logic. Secondly minification leads to smaller files and that gives less bandwidth usage (useful for large sites) and you spend less time downloading the file. This is pretty much essential for bigger websites and why not smaller ones as well. Javascript minifier tool closure works very well. Also don't forget to keep the original.

Source code viewer
  1. # Using tool made by Google to compress JavaScript file.
  2. closure-compiler --js_output_file compressed.js uncompressed.js
  3.  
  4. # Using tool made by Yahoo! to compress JavaScript file.
  5. yuicompressor uncompressed.js -o compressed.js
Programming Language: Bash