Loading... <p> 对于使用WordPress的Bloger来说,开启服务器的GZip压缩是一个为博客加速的好方法,GZip可对多种类型的文件进行压缩,对于CSS,JS,以及HTML文件更具有极高的压缩率,尤其当博客使用了比较多的JS特效,开启GZip后压缩比高达70%。说白了,如果你的博客首页有100KB的话,开启GZip后就成30KB了~但网友在浏览器端看到的东西是一样的,加速效果可想而知~本篇日志介绍的方法不仅适用于WordPress,任何网站都适用。 </p> <p>首先检测你的网站是否开启了 gzip功能:<span class="external-link"><a class="no-external-link" href="http://tool.chinaz.com/Gzips/" target="_blank"><i data-feather="external-link"></i>http://tool.chinaz.com/Gzips/</a></span></p> <p><strong>方法一:插件实现</strong> <br /> 插件名称:gzippy,下载地址:<span class="external-link"><a class="no-external-link" href="http://wordpress.org/extend/plugins/gzippy/" target="_blank"><i data-feather="external-link"></i>http://wordpress.org/extend/plugins/gzippy/</a></span> <br /> 对于喜欢偷懒不喜欢折腾的人的确方便得很,下载激活即可,没有其他更多的设置。 <br /><strong>方法二:php.ini 实现</strong> <br /> 新建一个文本文件,输入以下的内容,保存为 php.ini 文件上传到网站根目录即可。 <br />output_buffering = Off <br />output_handler = <br />zlib.output_compression = On <br /><strong>方法三:修改index.php文件</strong> <br /> 在根目录index.php文件中找到1    define(‘WP_USE_THEMES’, true); </p> <p>在后面加入下面的代码即可: <br />1    ob_start(‘ob_gzhandler’); </p> <p><strong>方法四:修改.htaccess</strong> <br />将以下代码拷贝到.htaccess文件中,上传至网站根目录中即可~ <br /><IfModule mod_deflate.c> <br /># Insert filters <br />AddOutputFilterByType DEFLATE text/plain <br />AddOutputFilterByType DEFLATE text/html <br />AddOutputFilterByType DEFLATE text/xml <br />AddOutputFilterByType DEFLATE text/css <br />AddOutputFilterByType DEFLATE application/xml <br />AddOutputFilterByType DEFLATE application/xhtml+xml <br />AddOutputFilterByType DEFLATE application/rss+xml <br />AddOutputFilterByType DEFLATE application/javascript <br />AddOutputFilterByType DEFLATE application/x-javascript <br />AddOutputFilterByType DEFLATE application/x-httpd-php <br />AddOutputFilterByType DEFLATE application/x-httpd-fastphp <br />AddOutputFilterByType DEFLATE image/svg+xml </p> <p>适用于VPS或者DS。在配置服务器时,将Apache2.x系列已经内置了的Deflate模块一并安装即可。具备此模块的共享空间同样适用。mod_deflate模块配置相对灵活,推荐安装。 <br />     由于gif,jpg格式的图片本身已经是经过压缩的格式,所以不要指望GZip还能为你榨出多少水分,png的图片效果倒是不错~ <br />    其实还有其他一些方法,这里就不多介绍了,想要了解的可以自己 google 一下。任选以上其中一种,修改后,重新检测你的网页是否已开启 Gzip 吧。</p> Last modification:October 6, 2023 © Allow specification reprint Support Appreciate the author AliPayWeChat Like 如果觉得我的文章对你有用,请随意赞赏