Created
September 26, 2012 08:56
-
-
Save michaelbramwell/3786894 to your computer and use it in GitHub Desktop.
Google Closure JS Minify for C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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