我正在寻找一个PHP脚本或类,可以缩小我的PHP页面html输出像谷歌页面速度.
我怎样才能做到这一点?
我正在使用此代码来缩小wordpress中的HTML输出.它在主页面和帖子页面上都很完美,但在管理部分它会导致很多问题.
function minify_html(){
ob_start('html_compress');
}
function html_compress($buffer){
$search = array(
'/\n/', // replace end of line by a space
'/\>[^\S ]+/s', // strip whitespaces after tags, except space
'/[^\S ]+\</s', // strip whitespaces before tags, except space
'/(\s)+/s', // shorten multiple whitespace sequences,
'~<!--//(.*?)-->~s' //html comments
);
$replace = array(
' ',
'>',
'<',
'\\1',
''
);
$buffer = preg_replace($search, $replace, $buffer);
return $buffer;
}
add_action('wp_loaded','minify_html');
Run Code Online (Sandbox Code Playgroud)
使用'the_post'代替'wp_loaded'只会缩小帖子,但我希望能够将主页面和帖子页面缩小到100%,但管理部分没有任何内容.如何组合操作以进行管理?
谢谢!