我所有的 .html 和 .php 网页都应该被缩小。这意味着我希望删除所有 HTML 注释和多个空格字符。
是否存在用于缩小的 Apache 模块?
(或者也许是在输出发送给用户之前直接自动添加脚本的另一种方法?)
(我可以添加如下函数,但如果存在 Apache 模块或其他自动解决方案,我不会忘记这样做。)
<?
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
);
$replace = array(
'>',
'<',
'\\1'
);
$buffer = preg_replace($search, $replace, $buffer);
return $buffer;
}
?>
最佳答案
试试 mod_pagespeed这可能对你有用。
关于apache - 如何自动缩小我的网页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7606433/