MiniME - API

Programatically invoking MiniME

In addition to the command line tool, MiniME can also be invoked programmatically through

a programming interface (API) from any .NET client program. This can be used to dynamically

obfuscate JavaScript files directly on an ASP.NET server.

  1. Before using MiniME programmatically, you must add a reference to it from your .NET project.

Depending on your development environment this might be done in any of a number of different ways -

please consult the documentation for your development tool.

  1. Create an instance of the MiniMI Compiler object. eg:

    
    // Create an instance of the MiniME minifier
    
    var mm = new MiniME.Compiler();
    
  2. Set MiniME options. eg:

    
    // Setup options
    
    mm.MaxLineLength = 0;
    
  3. Add files to process:

    
    // Add files
    
    mm.AddFile("MyJavaScriptFile.js", Encoding.UTF8)
    

    or, add script directly

    
    mm.AddScript("snippet", "<javascript code here>");
    
  4. Compile the script

    
    // Compile and write to an output file
    
    mm.OutputFileName="MyMinifiedFile.js";
    
    mm.OutputEncoding=Encoding.UTF8;
    
    mm.Compile();
    

    or, compile to a string

    
    var ObfuscatedScript=mm.CompileToString();
    
  5. That's it!

See also Command Line and MiniME In-script Directives.