This site has been acquired by Toptal.com.
(Attention! API endpoint has changed)

JavaScript Minifier

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

Java

Thanks to Cleber Muramoto for this contribution.

final URL url = new URL("https://www.toptal.com/developers/javascript-minifier/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");
}

Click on the language of your choice to see an example: