YUI Compressor

Yahoo Compressor can compress both JavaScript and CSS files.

http://yui.github.io/yuicompressor/

Usage for JavaScript

compressor.minify({
  compressor: 'yui-js',
  input: 'foo.js',
  output: 'bar.js',
  callback: function(err, min) {}
});

Usage for CSS

compressor.minify({
  compressor: 'yui-css', // OR 'yui'
  input: 'foo.js',
  output: 'bar.js',
  callback: function(err, min) {}
});

Java

WARNING

It assumes that you have Java installed on your environment.

To check, run:

java -version

How to install:

Mac: https://java.com/en/download/help/mac_install.xml

Windows: https://java.com/en/download/help/windows_manual_download.xml

Linux: https://www.java.com/en/download/help/linux_x64_install.xml

Options

compressor.minify({
  compressor: 'yui-js',
  input: 'foo.js',
  output: 'bar.js',
  options: {
    'line-break': 80,
    charset: 'utf8'
    ... // See more information link below
  },
  callback: function (err, min) {}
});

Check all options