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.

Python

Credits: Thanks to Cristian Tomatis for contributing this example.

import requests

url = 'https://www.toptal.com/developers/javascript-minifier/raw'
data = {'input': open('ready.js', 'rb').read()}
response = requests.post(url, data=data)

print response.text

Python - from the REPL

Credits: Thanks to Noam Yorav-Raphael for contributing this example.

>>> import requests
>>> requests.post('https://www.toptal.com/developers/javascript-minifier/raw', data=dict(input='var a = 1;')).text
'var a=1;'

Python - a CLI tool

Credits: Thanks to Kyle S. for contributing this to the site.

# -*- coding: utf-8 -*-
import sys
import requests

try:
    js_file = sys.argv[1]
except:
    print("Missing input file")
    sys.exit()

# Grab the file contents
with open(js_file, 'r') as c:
    js = c.read()

# Pack it, ship it
payload = {'input': js}
url = 'https://www.toptal.com/developers/javascript-minifier/raw'
print("Requesting mini-me of {}. . .".format(c.name))
r = requests.post(url, payload)

# Write out minified version
minified = js_file.rstrip('.js')+'.min.js'
with open(minified, 'w') as m:
    m.write(r.text)

print("Minification complete. See {}".format(m.name))

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