Minify your JavaScript

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

Digital Ocean

Written and hosted by Andrew Chilton (@andychilton).

We recommend Digital Ocean for hosting your sites. Free $10 credit when you sign up.

PHP

<?php
    // setup the URL, the JavaScript and the form data
    $url = 'https://javascript-minifier.com/raw';
    $js = file_get_contents('./public/s/js/ready.js');
    $data = array(
        'input' => $js,
    );

    // init the request, set some info, send it and finally close it
    $ch = curl_init($url);

    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $minified = curl_exec($ch);

    curl_close($ch);

    // output the $minified
    echo $minified;
?>

Also, Toni Almeida has made a PHP library to easily talk to JavaScript Minifier : https://github.com/promatik/PHP-JS-CSS-Minifier.

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.