Minify your JavaScript

Online JavaScript Minifier/Compressor. Free! Provides an API. Simple Quick and Fast.

Written and hosted by Andrew Chilton (@andychilton).

C# Async Example

Thanks to Dennis Janiak for contributing this example.

public static class JavaScripMinifier
    private const string URL_JS_MINIFIER       = "";
    private const string POST_PAREMETER_NAME    = "input";

    public static async Task<String> MinifyJs(string inputJs)
        List<KeyValuePair<String, String>> contentData = new List<KeyValuePair<String, String>>
            new KeyValuePair<String, String>(POST_PAREMETER_NAME, inputJs)

        using (HttpClient httpClient = new HttpClient())
            using (FormUrlEncodedContent content = new FormUrlEncodedContent(contentData))
                using (HttpResponseMessage response = await httpClient.PostAsync(URL_JS_MINIFIER, content))
                    return await response.Content.ReadAsStringAsync();


using (Task<String> task = JavaScriptMinifier.MinifyJs("/* comment */ console.log( 1 );   "))
    Console.WriteLine(task.Result); // input{font-size:9pt}

C# Example

Thanks to Juan Herrera for contributing this example.

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("");
request.Method = "POST";
string formContent = "input=" + jsContent.Text;
byte[] byteArray = Encoding.UTF8.GetBytes(formContent);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;

Stream str = request.GetRequestStream();
str.Write(byteArray, 0, byteArray.Length);

WebResponse response = request.GetResponse();
str = response.GetResponseStream();
if (str != null)
  StreamReader reader = new StreamReader(str);
  jsMinified.Text = reader.ReadToEnd();

Language Examples

Click on the language of your choice:

wget Curl Node.js Python Java Ruby Perl PHP C# Rust Kotlin

More Languages

I'd love to add more examples in your favourite programming language, so feel free to send them my way. Email andychilton at that gmail place in the sky or tweet to me @andychilton.