I have this code in my init file, to make my html size smaller for visitors and this helps me when reading the html code.
function sanitize_output($buffer) {
$search = array(
'/\>[^\S ]+/s',
'/[^\S ]+\</s',
'/(\s)+/s'
);
$replace = array(
'>',
'<',
'\\1'
);
$blocks = preg_split('/(<\/?pre[^>]*>)/', $buffer, null, PREG_SPLIT_DELIM_CAPTURE);
$buffer = '';
foreach($blocks as $i => $block)
{
if($i % 4 == 2)
$buffer .= $block;
else
$buffer .= preg_replace($search, $replace, $block);
}
return $buffer;
}
ob_start("sanitize_output");
Problem is that the page load time increased from (.9s - 1.2s) to (1.9s - 2.6s). And I read the answer here https://stackoverflow.com/a/9943436/7059329, stating that ob_start()
will affect the page load times. How can I make the load time faster? Should I remove the ob_start()
code?