先上图,看前后对比,压缩比竟然高达76.92%,哇哈哈~~~~!
压缩前:
压缩后:
本着能不用插件就不用插件的原则,这次开启wordpress网页压缩功能就使用了一句代码,省去了安装wp-super-cache等插件。通过PHP函数的方式来启动网页压缩,但前提是系统必须支持Zlib Compression Functions。修改网站根目录(不是主题目录)下的index.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压缩的网址: