Minify your JavaScript

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

w3tees

Support JavaScript Minifier by purchasing a w3tees t-shirt. This site is also run by us.

Java

Thanks to Cleber Muramoto for this contribution.

final URL url = new URL("https://javascript-minifier.com/raw");

// JS File you want to compress
byte[] bytes = Files.readAllBytes(Paths.get(...));

final StringBuilder data = new StringBuilder();
data.append(URLEncoder.encode("input", "UTF-8"));
data.append('=');
data.append(URLEncoder.encode(new String(bytes), "UTF-8"));

bytes = data.toString().getBytes("UTF-8");

final HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("charset", "utf-8");
conn.setRequestProperty("Content-Length", Integer.toString(bytes.length));

try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {
    wr.write(bytes);
}

final int code = conn.getResponseCode();

System.out.println("Status: " + code);

if (code == 200) {
    System.out.println("----");
    final BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String inputLine;

    while ((inputLine = in.readLine()) != null) {
        System.out.print(inputLine);
    }
    in.close();

    System.out.println("\n----");
} else {
    System.out.println("Oops");
}

Language Examples

Click on the language of your choice:

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

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.