如何自动缩小我的网页?
我所有的 .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;
}
?>
All of my .html and .php webpages should be minified. That means I would like to get all HTML-comments and more than one whitespace-character stripped.
Does an Apache-module exist for minification?
(Or perhaps another method to automatically add a script directly before the output gets sent to the user?)
(I could add a function like the following, but if an Apache-module or another automatic solution existed, I could not forget to do so.)
<?
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;
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试mod_pagespeed,这可能对您有用。
Try mod_pagespeed which may be of some use to you.