Created
August 31, 2018 10:41
-
-
Save udovichenko/c9da4722eefb4088a5348235d3620088 to your computer and use it in GitHub Desktop.
MODX Plugin htmlMinify
This file contains hidden or 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
<?php | |
$e =& $modx->event; | |
switch ($e->name) { | |
case "OnWebPagePrerender": { | |
$output = &$modx->resource->_output; | |
$search = array( | |
'/\>[^\S ]+/s', // strip whitespaces after tags, except space | |
'/[^\S ]+\</s', // strip whitespaces before tags, except space | |
'/(\s)+/s', // shorten multiple whitespace sequences | |
'/<!--(.|\s)*?-->/' // Remove HTML comments | |
); | |
$replace = array( | |
'>', | |
'<', | |
'\\1', | |
'' | |
); | |
$output = preg_replace($search, $replace, $output); | |
$modx->resource->_output = $output; | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment