Minify your CSS

Online CSS 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 and read the CSS from a file
    $url = 'https://cssminifier.com/raw';
    $css = file_get_contents('styles.css');

    // init the request, set various options, and send it
    $ch = curl_init();

    curl_setopt_array($ch, [
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POST => true,
        CURLOPT_HTTPHEADER => ["Content-Type: application/x-www-form-urlencoded"],
        CURLOPT_POSTFIELDS => http_build_query([ "input" => $css ])
    ]);

    $minified = curl_exec($ch);

    // finally, close the request
    curl_close($ch);

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

Thanks to Boudewijn van Breukelen for an updated version of the above code.

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

Language Examples

Click on the language of your choice:

wget Curl Node.js Python 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.