Yea, there is this class available on github https://github.com/matthiasmullie/minify But I wouldn't recommend doing this at run time, not sure if you were planning on doing that but yea
API that takes care of code and has no limit of minifying (so far). You can use this service using curl within php like this: 1. Create a function for posting your file data to API function curl_post($url, $post="") { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_POST, $post); curl_setopt($ch, CURLOPT_POSTFIELDS, is_array($post) ? http_build_query($post) : $post); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $server_output = curl_exec ($ch); curl_close ($ch); return $server_output; } PHP: 2. Minifying your CSS file $css_data = file_get_contents('my_old.css'); $new_data = json_decode(curl_post('http://servicebull.com/minify-css', $css_data), TRUE); //for display use print $new_data['data']['minified'] //for saving css back file_put_contents('my_new.css', $new_data['data']['minified']); PHP: 3. Minifying your JS file $js_data = file_get_contents('my_old.js'); $new_data = json_decode(curl_post('http://servicebull.com/minify-js', $js_data), TRUE); //for display use print $new_data['data']['minified']; //for saving jsback file_put_contents('my_new.js', $new_data['data']['minified']); PHP: 4. Minifying your HTML file $html_data = file_get_contents('my_old.html'); $new_data = json_decode(curl_post('http://servicebull.com/minify-html', $js_data), TRUE); //for display use print $new_data['data']['minified']; //for saving jsback file_put_contents('my_new.html', $new_data['data']['minified']); PHP: BTW : You can print_r($new_data) to see the difference and size reduction as well. NOTE: http://servicebull.com/<SERVICE NAME HERE> i.e. minify-css / minify-js / minify-html I hope it helps. stay well....
One correction It should be: $new_data['data']['output'] PHP: Instead of $new_data['data']['minified'] stay well...