考虑下面的链接来缩小JavaScript /CSS文件:https://github.com/mrclay/minify
告诉Apache使用GZip交付HTML——这通常会将响应大小减少约70%.(如果使用Apache,配置gzip的模块取决于您的版本:Apache 1.3使用mod_gzip,而Apache 2.x使用mod_deflate.)
接受编码:gzip,deflate
内容编码:gzip
使用following snippet在帮助ob_start的缓冲区中删除HTML中的空白:
<?php
function sanitize_output($buffer) {
$search = array(
'/\>[^\S ]+/s', // strip whitespaces after tags, except space
'/[^\S ]+\</s', // strip whitespaces before tags, except space
'/(\s)+/s', // shorten multiple whitespace sequences
'/<!--(.|\s)*?-->/' // Remove HTML comments
);
$replace = array(
'>',
'<',
'\\1',
''
);
$buffer = preg_replace($search, $replace, $buffer);
return $buffer;
}
ob_start("sanitize_output");
?>