wordpress一行代码开启Gzip网页压缩


先上图,看前后对比,压缩比竟然高达76.92%,哇哈哈~~~~!

压缩前:

wordpress开启Gzip压缩

压缩后:

wordpress开启Gzip压缩

本着能不用插件就不用插件的原则,这次开启wordpress网页压缩功能就使用了一句代码,省去了安装wp-super-cache等插件。通过PHP函数的方式来启动网页压缩,但前提是系统必须支持Zlib Compression Functions。修改网站根目录(不是主题目录)下的index.php文件。


<?php
ob_start('ob_gzhandler');//只加上这句代码即可开启GZip
/**
 * Front to the WordPress application. This file doesn't do anything, but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */

/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */
define('WP_USE_THEMES', true);

/** Loads the WordPress Environment and Template */
require('./wp-blog-header.php');

下面是几个测试网站是否启用gzip压缩的网址:

http://tool.chinaz.com/Gzips/Default.aspx

http://gzip.zzbaike.com/

http://www.websiteoptimization.com/services/analyze/

2 Responses Comment (2) Trackback (0)
  1. dang :

    哦!好吧,昨天刚查了这个东东! :idea:

    1. SingleX Post author :

      很好很强大,是不是~~

发表评论