Skip to content

Instantly share code, notes, and snippets.

@andrewspear
Last active August 29, 2015 14:01
Show Gist options
  • Save andrewspear/48fccb3290824462f460 to your computer and use it in GitHub Desktop.
Save andrewspear/48fccb3290824462f460 to your computer and use it in GitHub Desktop.
Minify HTML/JS/CSS Output with PHP
<?
/*
Description: Place this code at the top of your PHP page to minify all of it's HTML output
Dependencies: https://code.google.com/p/minify/
*/
function sanitize_output($buffer) {
require_once('min/lib/Minify/HTML.php');
require_once('min/lib/Minify/CSS.php');
require_once('min/lib/JSMin.php');
$buffer = Minify_HTML::minify($buffer, array(
'cssMinifier' => array('Minify_CSS', 'minify'),
'jsMinifier' => array('JSMin', 'minify')
));
return $buffer;
}
ob_start('sanitize_output');
?>
@thinkpozzitive
Copy link

The above code will break on a HTML document on the <style> declaration in the header. Any way to get around it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment