Last active
August 29, 2015 14:01
-
-
Save andrewspear/48fccb3290824462f460 to your computer and use it in GitHub Desktop.
Minify HTML/JS/CSS Output with PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
/* | |
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'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The above code will break on a HTML document on the <style> declaration in the header. Any way to get around it?