<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>睡到25点 &#187; gzip</title>
	<atom:link href="http://www.voidman.com/tag/gzip/feed" rel="self" type="application/rss+xml" />
	<link>http://www.voidman.com</link>
	<description>个人博客，记录与分享。</description>
	<lastBuildDate>Thu, 12 Jan 2012 14:00:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>让 GZIP 与 cos-html-cache 共存</title>
		<link>http://www.voidman.com/2008/03/wordpress-can-coexist-with-gizp-and-cos-html-cache.html</link>
		<comments>http://www.voidman.com/2008/03/wordpress-can-coexist-with-gizp-and-cos-html-cache.html#comments</comments>
		<pubDate>Fri, 14 Mar 2008 07:07:09 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Blog Related]]></category>
		<category><![CDATA[cos-html-cache]]></category>
		<category><![CDATA[gzip]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[静态化]]></category>

		<guid isPermaLink="false">http://www.voidman.com/2008/03/wordpress-can-coexist-with-gizp-and-cos-html-cache.html</guid>
		<description><![CDATA[用过 cos-html-cache 插件的人都知道，cos-html-cache 需要在 WordPress 后台关闭 gzip 压缩选项才能正常工作。因为 cos-html-cache 只静态化首页和日志页面，这样一来像分类浏览页面、按日期浏览页面、搜索结果页面等等既没有静态化，也没有享受到 gzip 压缩带来的好处。 其实有时候鱼和熊掌还是可以兼得的。Wordpress 后台的 gzip 压缩设置是个全局选项，它不区分页面类型，那么我们可以手动对需要压缩的页面启用 gzip 。将以下代码添加到主题目录下的 functions.php header.php 文件中的 HTML 代码之前： &#60;?php // 下面的代码大部分来自 Wordpress 的 gzip_compression 函数 // 如果关闭了 gzip 并且启用了 cos-html-cache 插件 if &#40; !get_option&#40; 'gzipcompression' &#8230; <a href="http://www.voidman.com/2008/03/wordpress-can-coexist-with-gizp-and-cos-html-cache.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>用过 <a href="http://www.storyday.com/html/y2008/1446_cos-html-cache-upgrade.html" rel="external nofollow">cos-html-cache</a> 插件的人都知道，cos-html-cache 需要在 WordPress 后台关闭 gzip 压缩选项才能正常工作。因为 cos-html-cache 只静态化首页和日志页面，这样一来像分类浏览页面、按日期浏览页面、搜索结果页面等等既没有静态化，也没有享受到 gzip 压缩带来的好处。</p>
<p>其实有时候鱼和熊掌还是可以兼得的。Wordpress 后台的 gzip 压缩设置是个全局选项，它不区分页面类型，那么我们可以手动对需要压缩的页面启用 gzip 。将以下代码添加到主题目录下的 <del datetime="20080315">functions.php</del> header.php 文件中的 HTML 代码之前：</p>

<div class="wp_syntax"><pre class="php"><span style="color: blue;">&lt;?php</span>
<span style="color: #008000; font-style: italic;">// 下面的代码大部分来自 Wordpress 的 gzip_compression 函数</span>
<span style="color: #008000; font-style: italic;">// 如果关闭了 gzip 并且启用了 cos-html-cache 插件</span>
<span style="color: blue;">if</span> <span style="color: #800000;">&#40;</span> !get_option<span style="color: #800000;">&#40;</span> <span style="color: #ff00ff;">'gzipcompression'</span> <span style="color: #800000;">&#41;</span> &amp;&amp; <span style="color: #ff0000;">function_exists</span><span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">'CosSafeTag'</span><span style="color: #800000;">&#41;</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#123;</span>
  <span style="color: #008000; font-style: italic;">// 如果不是日志页或者首页</span>
  <span style="color: blue;">if</span><span style="color: #800000;">&#40;</span>!<span style="color: #800000;">&#40;</span>is_single<span style="color: #800000;">&#40;</span><span style="color: #800000;">&#41;</span> || <span style="color: #800000;">&#40;</span>is_home<span style="color: #800000;">&#40;</span><span style="color: #800000;">&#41;</span> &amp;&amp; !is_paged<span style="color: #800000;">&#40;</span><span style="color: #800000;">&#41;</span><span style="color: #800000;">&#41;</span><span style="color: #800000;">&#41;</span><span style="color: #800000;">&#41;</span><span style="color: #800000;">&#123;</span>
    <span style="color: blue;">if</span> <span style="color: #800000;">&#40;</span> <span style="color: #800000;">&#40;</span> <span style="color: #ff0000;">ini_get</span><span style="color: #800000;">&#40;</span> <span style="color: #ff00ff;">'zlib.output_compression'</span> <span style="color: #800000;">&#41;</span> == <span style="color: #ff00ff;">'On'</span> || <span style="color: #ff0000;">ini_get</span><span style="color: #800000;">&#40;</span> <span style="color: #ff00ff;">'zlib.output_compression_level'</span> <span style="color: #800000;">&#41;</span> &gt; <span style="color: #800080;">0</span> <span style="color: #800000;">&#41;</span> || <span style="color: #ff0000;">ini_get</span><span style="color: #800000;">&#40;</span> <span style="color: #ff00ff;">'output_handler'</span> <span style="color: #800000;">&#41;</span> == <span style="color: #ff00ff;">'ob_gzhandler'</span> <span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#123;</span>
      <span style="color: #008000; font-style: italic;">// Do nothing</span>
    <span style="color: #800000;">&#125;</span> <span style="color: blue;">else</span> <span style="color: #800000;">&#123;</span>
      <span style="color: blue;">if</span> <span style="color: #800000;">&#40;</span> <span style="color: #ff0000;">extension_loaded</span><span style="color: #800000;">&#40;</span> <span style="color: #ff00ff;">'zlib'</span> <span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#123;</span>
        <span style="color: #ff0000;">ob_start</span><span style="color: #800000;">&#40;</span> <span style="color: #ff00ff;">'ob_gzhandler'</span> <span style="color: #800000;">&#41;</span>;
      <span style="color: #800000;">&#125;</span>
    <span style="color: #800000;">&#125;</span>
  <span style="color: #800000;">&#125;</span>
<span style="color: #800000;">&#125;</span>
<span style="color: blue;">?&gt;</span></pre></div>

<p>本来也没想到要这么做，因为<a href="http://www.voidman.com/2008/03/wordpress-404-page-not-work-well-in-ie.html">折腾 WordPress 的 404 页面</a>过程中发现打开 gzip 后 IE 就可以正常显示错误页面，索性将其它没有被静态化的页面一并压缩了。</p>
<p><strong>UPDATE</strong> at 2008-3-15 21:37<br />
刚才再次测试的时候才发现上面那段代码放在 functions.php 中会工作不正常，因为 WP 加载 functions.php 的时候还没执行查询操作，is_single() 判断根本就不起作用。惭愧，有些粗心大意了。</p>
<h4>Related Posts</h4><ul class="related_post"><li><a href="http://www.voidman.com/2008/11/the-better-solution-for-static-paged-post.html" title="Wordpress 分页文章静态化的更优解决方案">Wordpress 分页文章静态化的更优解决方案</a></li><li><a href="http://www.voidman.com/2008/03/trouble-with-static-wordpress.html" title="Wordpress 静态化的烦恼">Wordpress 静态化的烦恼</a></li><li><a href="http://www.voidman.com/2008/03/create-static-html-files-for-paged-post.html" title="让 Wordpress 分页文章也可以静态化">让 Wordpress 分页文章也可以静态化</a></li><li><a href="http://www.voidman.com/2009/05/using-wordpress-plugin-api-hack-discuz.html" title="WordPress 的 Hook 机制在 Discuz 二次开发中的应用">WordPress 的 Hook 机制在 Discuz 二次开发中的应用</a></li><li><a href="http://www.voidman.com/2009/04/at-reply-mail-notification-1-release.html" title="At Reply Mail Notification 1.0 Release">At Reply Mail Notification 1.0 Release</a></li><li><a href="http://www.voidman.com/2009/03/lbs-to-wordpress.html" title="LBS 转 WordPress 不完全记录">LBS 转 WordPress 不完全记录</a></li><li><a href="http://www.voidman.com/2009/01/wordpress-is-using-a-bad-way-to-detect-duplicate-comment.html" title="Wordpress 糟糕的重复评论检测方式">Wordpress 糟糕的重复评论检测方式</a></li><li><a href="http://www.voidman.com/2009/01/at-reply-mail-notification-test.html" title="At Reply Mail Notification 测试贴">At Reply Mail Notification 测试贴</a></li><li><a href="http://www.voidman.com/2008/11/automatically-delete-post-revisions.html" title="让 Wordpress 自动删除 Post Revisions">让 Wordpress 自动删除 Post Revisions</a></li><li><a href="http://www.voidman.com/2008/11/google-xml-sitemaps-ignore-the-specified-categories.html" title="让 Google Sitemaps Generator 可以忽略指定的日志分类">让 Google Sitemaps Generator 可以忽略指定的日志分类</a></li></ul><hr /><a href="http://www.voidman.com">Voidman.com</a> | Link: <a href="http://www.voidman.com/2008/03/wordpress-can-coexist-with-gizp-and-cos-html-cache.html">http://www.voidman.com/2008/03/wordpress-can-coexist-with-gizp-and-cos-html-cache.html</a><br /><img alt="linezing" width="1" height="1" src="http://img.tongji.linezing.com/288120/tongji.gif" />]]></content:encoded>
			<wfw:commentRss>http://www.voidman.com/2008/03/wordpress-can-coexist-with-gizp-and-cos-html-cache.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

