I found the html minification code on the Internet. I would like to ask the knowledgeable, is there any sense from such a code? I am also interested in the possible load from using this code. I would also like to know which of the three options is better ?
In index.php which is at the root of the site above the line
@ob_start ();
insert code (option 1)
function sanitize_output($buffer) {
$search = array('/\>[^\S ]+/s', '/[^\S ]+\</s', '/(\s)+/s', '/<!--(.*?)-->/', '/\>[^\S ]+/s', '/[^\S ]+\</s', '/(\s)+/s');
$replace = array('>', '<', '\\1', '', '>', '<', '\\1');
$buffer = preg_replace($search, $replace, $buffer);
return $buffer;
}
OR option 2
function sanitize_output($buffer) {
$search = array('/\>[^\S ]+/s', '/[^\S ]+\</s', '/(\s)+/s', '/<!--(.*?)-->/', '/\>[^\S ]+/s', '/[^\S ]+\</s', '/(\s)+/s');
$replace = array('>', '<', '\\1', '<!--\\1-->', '>', '<', '\\1');
$buffer = preg_replace($search, $replace, $buffer);
return $buffer;
}
OR option 3
function sanitize_output($buffer) {
$search = array(
'/\>[^\S ]+/s',
'/[^\S ]+\</s',
'/\s{5,}/'
);
$replace = array(
'>',
'<',
'\\1'
);
$buffer = preg_replace($search, $replace, $buffer);
return $buffer;
}
Next in /engine/modules/main.php find
echo $tpl->result['main'];
replace with
ob_start("sanitize_output");
echo $tpl->result['main'];
ob_end_flush();