我在我的init文件中有这个代码,为访问者缩小我的html大小,这有助于我阅读HTML代码。
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");
问题是页面加载时间从(.9s - 1.2s)增加到(1.9s - 2.6s)。我在这里阅读了答案https://stackoverflow.com/a/9943436/7059329,声明ob_start()
会影响页面加载时间。如何加快加载时间?我应该删除ob_start()
代码吗?