Skip to content

Instantly share code, notes, and snippets.

@michaelbramwell
Created September 26, 2012 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelbramwell/3786894 to your computer and use it in GitHub Desktop.
Save michaelbramwell/3786894 to your computer and use it in GitHub Desktop.
Google Closure JS Minify for C#
using System;
using System.Net;
using System.IO;
using System.Web;
/// <summary>
/// Minify js
/// Dependancy - PostSubmitter class = http://geekswithblogs.net/rakker/archive/2006/04/21/76044.aspx, can easily be replaced with native http post
/// </summary>
public partial class Crown_GoogleClosure : System.Web.UI.Page
{
private const String url = "http://closure-compiler.appspot.com/compile";
public void Page_Load(object sender, EventArgs e)
{
///////////////////////////////////////////////////////////////////
// js
String path = HttpContext.Current.Server.MapPath("~/");
String preMinified = File.ReadAllText(path + "/js/fileA.js");
preMinified += File.ReadAllText(path + "/js/fileB.js");
PostSubmitter post = new PostSubmitter();
post.Url = url;
post.PostItems.Add("compilation_level", "SIMPLE_OPTIMIZATIONS");
post.PostItems.Add("output_format", "text");
post.PostItems.Add("output_info", "compiled_code");
post.PostItems.Add("js_code", preMinified);
post.Type = PostSubmitter.PostTypeEnum.Post;
File.WriteAllText(path + "/js/projectname.min.js", post.Post());
///////////////////////////////////////////////////////////////////
feedback.Text = "Success";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment