CSS和Javascript
HTML
告诉Apache使用GZip提供HTML - 这通常会使响应大小减少约70%。(如果你使用Apache,配置gzip的模块取决于你的版本:Apache 1.3使用mod_gzip,而Apache 2.x使用mod_deflate。)Accept-Encoding:gzip,deflate
内容编码:gzip
使用以下代码段使用帮助ob_start的缓冲区从HTML中删除空格:<?phpfunction sanitize_output($buffer) {
$search = array(
'/\>[^\S ]+/s', // strip whitespaces after tags, except space
'/[^\S ]+\
'/(\s)+/s', // shorten multiple whitespace sequences
'//' // Remove HTML comments
);
$replace = array(
'>',
'
'\\1',
''
);
$buffer = preg_replace($search, $replace, $buffer);
return $buffer;}ob_start("sanitize_output");?>