<?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>Bolo的博客 &#187; Gzip</title>
	<atom:link href="http://blog.imbolo.com/tag/gzip/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.imbolo.com</link>
	<description>一个设计爱好者杂七杂八的博客</description>
	<lastBuildDate>Wed, 23 Nov 2011 16:19:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>BlueHost Gzip优化JS和CSS传输</title>
		<link>http://blog.imbolo.com/bluehost-gzip/</link>
		<comments>http://blog.imbolo.com/bluehost-gzip/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 03:17:51 +0000</pubDate>
		<dc:creator>bolo</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Bluehost]]></category>
		<category><![CDATA[Gzip]]></category>
		<category><![CDATA[Hosting]]></category>

		<guid isPermaLink="false">http://blog.imbolo.com/?p=1708</guid>
		<description><![CDATA[Bluehost是美国一个著名的主机商，以稳定性著称，全球有超过100万个网站托管在那里详细的介绍可以看鱼叔的介绍。我使用Bluehost已经有差不多两个月了，从刚开始购入这款主机起我一直断断续续地对我的博客进行优化，使页面的打开速度能得到提升。]]></description>
			<content:encoded><![CDATA[<p>Bluehost是美国一个著名的主机商，以稳定性著称，全球有超过100万个网站托管在那里详细的介绍可以看<a href="http://fairyfish.net/2010/02/09/bluehost/" rel="external nofollow">鱼叔的介绍</a>。我使用Bluehost已经有差不多两个月了，从刚开始购入这款主机起我一直断断续续地对我的博客进行优化，使页面的打开速度能得到提升。Bluehost对页面传输的优化比较怪，html文件默认是进行Gzip进行压缩的，但对CSS和JS文件不进行压缩，自己也不可以通过.htaccess文件让mod_deflate对CSS和JS文件进行压缩。今天我们只需要使用mod_rewrite提供的功能就可以实现全站CSS和JS压缩。<span id="more-1708"></span></p>
<h3>1.使用Minify库进行压缩</h3>
<p>Minify是Google Code上的一个开源项目（具体介绍可以看<a href="http://code.google.com/p/minify/" rel="external">这个页面</a>），作者整合了国外多个专家的研究成果，形成了一个功能强大的库，有很多大型站点也在使用这个库进行压缩。</p>
<h4>使用方法</h4>
<p>首先下载Minify的最新版本，把压缩包里的min目录上传到站点根目录，然后打开.htaccess编写rewrite rule：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="apache" style="font-family:monospace;">&lt;<span style="color: #000000; font-weight:bold;">ifmodule</span> mod_rewrite.c&gt;
<span style="color: #00007f;">RewriteEngine</span> <span style="color: #0000ff;">On</span>
<span style="color: #00007f;">RewriteBase</span> /
<span style="color: #00007f;">RewriteRule</span> ^(.*\.(css|js))$ min/index.php?f=$1&amp;debug=<span style="color: #ff0000;">0</span> [L,NC]
&lt;/<span style="color: #000000; font-weight:bold;">ifmodule</span>&gt;</pre></td></tr></table></div>

<h3>2.使用Combine.php进行压缩</h3>
<p>Combine.php是一个不知名的国外开发者写的一个小程序，同样可以压缩站点的CSS和JS文件，但与Minify相比Combine.php是超轻量级的，整个文件只有不到5K大小，大家可以点击<a href="http://cantonbolo.googlecode.com/files/combine.php" rel="external">这里下载</a>。下载后把文件上传到网站根目录，然后编写rewrite rule：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="apache" style="font-family:monospace;">&lt;<span style="color: #000000; font-weight:bold;">ifmodule</span> mod_rewrite.c&gt;
<span style="color: #00007f;">RewriteEngine</span> <span style="color: #0000ff;">On</span>
<span style="color: #00007f;">RewriteBase</span> /
<span style="color: #00007f;">RewriteRule</span> ^css/(.*\.css) /combine.php?type=css&amp;files=$1
<span style="color: #00007f;">RewriteRule</span> ^javascript/(.*\.js) /combine.php?type=javascript&amp;files=$1
&lt;/<span style="color: #000000; font-weight:bold;">ifmodule</span>&gt;</pre></td></tr></table></div>

<h3>后记</h3>
<p>这两个方法大家选其一使用，两个方法都是在服务器对所有CSS和JS先进行整合再传输，效率是比较高的，而且这两个方法也适合其他不能直接通过mod_deflate进行压缩的主机。下面是我优化前后的对比。</p>
<p><img src="http://i1001.photobucket.com/albums/af131/bolo1988/nonegzip.gif" alt="使用gzip前" /></p>
<p>使用Gzip压缩前文章页面的JS文件总体积达到100+K之巨。</p>
<p><img src="http://i1001.photobucket.com/albums/af131/bolo1988/activategzip.gif" alt="使用gzip压缩以后" /></p>
<p>使用Gzip压缩以后同一个页面的JS总体积已经被压缩到不足40K。虽然效果不及采用mod_deflate好，但我为了减少服务器负载只进行了轻度压缩，两个方法对于没有mod_deflate的主机来说是个折中的方法。</p>
<p>关于Bluehost降低服务器负担的方法可以看胡老板的《<a href="http://hugege.com/2009/12/01/php-ini/" rel="external nofollow">BlueHost/HostMonster修改文件上传大小限制和内存不足</a>》或Google其它优化技巧，我要说的是：Bluehost是一款非常耐玩的主机。</p>
<p  class="related_post_title">Related Posts</p><ul class="related_post"><li><a href="http://blog.imbolo.com/nginx-upgrade-to-0853/" title="NGINX 平滑升级到 0.8.53 小记">NGINX 平滑升级到 0.8.53 小记</a></li><li><a href="http://blog.imbolo.com/godaddy-grid-hosting/" title="GoDaddy Grid 主机">GoDaddy Grid 主机</a></li><li><a href="http://blog.imbolo.com/move-out/" title="移居国外">移居国外</a></li><li><a href="http://blog.imbolo.com/change-a-domain-and-how-to-change-a-main-domain-in-directadmin/" title="换个域名&#038;DA面板更换主域名教程">换个域名&#038;DA面板更换主域名教程</a></li><li><a href="http://blog.imbolo.com/got-a-hosting/" title="意外获得国外空间一个">意外获得国外空间一个</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.imbolo.com/bluehost-gzip/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

