Project Description
A compiler/minifier for JavaScript, built on Google Closure Compiler and YUI Compressor. It provides a .NET component for integration and a windows UI, allowing compilation of multiple source files in to one single file.

Overview

UI Compiler .NET provides a user interface and a .NET programming API to the most basic functionality of Google Closure Compiler and YUI Compressor.

UI Compiler .NET lets you merge multiple JavaScript files into one single, minified file. This approach will make your web page load and perform faster. The compiler will report errors and warnings. Since UI Compiler .NET has a core component, prividing an API, you can use it in your own applications or build scripts.

UI Compiler .NET can work directly with the Java application of Google Closure Compiler locally on your computer, or with its REST API. This means that you can use the REST API if you don't want to install Java on your computer or the local service (requires Java 6) if you want to compile/minify without having to access to the Internet. Note that the REST API cannot handle more than about 400 Kb input data.

Prerequisites

If you want to work locally with Gooble Closure Compiler, Java 6 or higher is required on any machine running _UI Compiler .NET.
UI Compiler .NET is built on .NET Framework 3.5.

Screenshot

UICompiler-screen1.jpg
Two files, with a total size of 18798 bytes are compiled into a single, minified file with a size of 6016 bytes.

Code example

The following code snippet shows how you can call UI Compiler .NET from your code. A more detailed specification of the API is included in the installation package.
using Interfleet.SE.UICompiler.Core;

// Create an agent factory, using the local compiler (a java component)
var agentFactory = CompileAgentFactory.CreateAgentFactory(CompileType.ClosureCompilerLocal);

// Build up arguments
var args = agentFactory.CreateArguments();
// Multiple files can be added, full filepaths are expected
args.Files.Add("c:\inputfile.js");
// full path of the compiled file
args.CompiledFileName = "c:\output.js";
args.CompileOption = "SIMPLE_OPTIMIZATIONS"

var closureCompilerAgent = agentFactory.CreateCompilerAgent(args);
// Compile
var result = closureCompilerAgent.Compile();

Output example

Input:
// -- function for determining how far horizontally the browser is scrolled
function scrollX() {
    // A shortcut, in case we´re using Internet Explorer 6 in Strict Mode
    var de = document.documentElement;

    // If the pageXOffset of the browser is available, use that
    return self.pageXOffset ||

        // Otherwise, try to get the scroll left off of the root node
        ( de && de.scrollLeft ) ||

        // Finally, try to get the scroll left off of the body element
       document.body.scrollLeft;
}
Output:
function scrollX(){var a=document.documentElement;return self.pageXOffset||a&&a.scrollLeft||document.body.scrollLeft}

Google Closure Compiler

Google Closure Compiler is distributed under the Apache Licence. Its documentation can be found here http://code.google.com/intl/sv/closure/compiler/

Last edited Feb 28, 2010 at 6:31 AM by swmal, version 22