Home » WordPress

zlib压缩WordPress

2 02月 2010 Views: No Comment Tags:

WordPress 默认状态下是不提供压缩代码输出到用户浏览器的,但只要简单的几行代码就可以达到我们需要的压缩输出的目的了,甚至可以压缩尽75%的内容。

首先,我们要做的就是检测自己所用的主机是否支持zlib(一个比较通用的压缩库,通过在程序中引入zlib,可以方便的对数据进行压缩),把下面的代码复制到一个新建的.php文件中,不妨叫它为test.php。

<?php phpinfo(); ?>

把test.php页面上传到你的主机,在浏览器中运行这个页面,看看参数中是否支持zlib。我所在的空间显示如下:

1261204AU9230-30I50

如果确定主机支持zlib,那么你可以继续往下做了。

把下面的代码复制到你主题的header文件中,在DOCTYPE之上

<?php
ini_set(‘zlib.output_compression’, ‘On’);
ini_set(‘zlib.output_compression_level’, ‘1′);
?>

就是这些,之后去Port80Software.com上看看是否压缩输出了吧。文章译自wprecipes.

原创文章如转载,请注明:转载自Xixis Blog [ http://www.xixis.net/ ]
本文链接地址:http://www.xixis.net/archives/zlib-compression-wordpress.html

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.