Skip to content

Instantly share code, notes, and snippets.

@reid
Created April 26, 2011 19:47
Show Gist options
  • Save reid/942972 to your computer and use it in GitHub Desktop.
Save reid/942972 to your computer and use it in GitHub Desktop.
Reid's YUI Compressor Fork HOWTO

Reid's YUI Compressor Fork

I've created a fork of YUI Compressor that will be integrated into a future official version. It makes YUI Compressor more friendly to build systems.

Warning

The code you're about to use and these instructions come with absolutely no warranty. See the LICENSE file for details.

Even though I'm on the YUI team, this is not yet a part of the official YUI project. It comes with zero support. This may break your builds and set fire to your office.

You should consider using the official version!

How to build

The changes I've made are on my fork's ant branch.

Requires Java 5 and Ant.

git clone git://github.com/reid/yuicompressor.git
git co ant
ant
# YUI Compressor is built to build/yuicompressor-2.4.7pre.jar

Native Ant support

You can embed YUI Compressor into your Ant build system. This method is used by YUI Builder to build YUI. Using this native task is much faster than invoking Compressor once per file on the command line.

<taskdef name="yuicompressor"
    classname="com.yahoo.platform.yui.compressor.CompressorTask"
    classpath="../path/to/yuicompressor-2.4.7pre.jar"/>

<!-- The options attribute takes command line flags. -->
<yuicompressor input="raw.js" output="compressed.js" options="--preserve-semi --line-break 8000"/>

HTTP Server

YUI Compressor now has a built-in HTTP server. Pass --server [port] to start it.

java -jar build/yuicompressor-2.4.7pre.jar --server 8000

You can then PUT requests to /compress?type=js and get back compressed script.

HTTP Compression API

/compress [HTTP PUT]

Compresses JavaScript or CSS.

Required query parameters:

  • type: either "js" or "css"

Optional query parameters:

  • output: "json" or "raw". If JSON, outputs JSON object with "result", the compressed script or stylesheet, and "warnings", "errors", which were generated from the compressor. Defaults to "raw", which is the raw compressed result. Warning: JSON output has problems with some UTF-8 text.
  • charset: Defaults to "UTF-8".
  • lineBreak: Break after this many characters.
  • semicolons: If true, preserve semicolons. Defaults to false.
  • munge: If false, don't munge variables. Defaults to true.
  • optimize: If false, disable optimizations. Defaults to true.

Author

Reid Burke rburke@yahoo-inc.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment