The Closure Compiler comes in two flavors – a Java based command line tool and a RESTful API. I’ve been playing around with the API and it works great and very fast.
public string Compress(string file)
string source = File.ReadAllText(file);
XmlDocument xml = CallApi(source);
private static XmlDocument CallApi(string source)
using (WebClient client = new WebClient())
string data = string.Format(PostData, HttpUtility.UrlEncode(source));
string result = client.UploadString(ApiEndpoint, data);
XmlDocument doc = new XmlDocument();
How to use it
GoogleClosure gc = new GoogleClosure();
string script = gc.Compress(Server.MapPath("~/script.js"));
Remember that the class doesn't do any exception handling, so you might want to stick that in yourself.