<?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>fish的航海日志 &#187; performance</title>
	<atom:link href="http://blog.v2op.com/tag/performance/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.v2op.com</link>
	<description>海到无边天做岸,山登绝顶我为峰</description>
	<lastBuildDate>Mon, 30 Jan 2012 04:30:13 +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>使用PHP压缩CSS的三种方法</title>
		<link>http://blog.v2op.com/2008/12/3-ways-to-compress-css-files-using-php/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=3-ways-to-compress-css-files-using-php</link>
		<comments>http://blog.v2op.com/2008/12/3-ways-to-compress-css-files-using-php/#comments</comments>
		<pubDate>Sat, 20 Dec 2008 16:11:50 +0000</pubDate>
		<dc:creator>AmirFish</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://blog.v2op.com/?p=259</guid>
		<description><![CDATA[一个网站通常包含多个css文件。网站越复杂，这些css文件也会越庞大，对它们进行适当的压缩，可以节约不少带宽（在访问量巨大的时候尤为明显）。 下面介绍三种使用PHP压缩css的方法。 第一种方法： 修改css的文件名，比如把 v2op.css 改成 v2op.css.php。调用的方式如下： &#60;link rel="stylesheet" type="text/css" media="screen" href="/v2op.css.php"/&#62; 然后修改此v2op.css.php，在文件开头加上 &#60;?php if(extension_loaded('zlib')){ob_start('ob_gzhandler');} header("Content-type: text/css"); ?&#62; 在文件最后面加上 &#60;?php if(extension_loaded('zlib')){ob_end_flush();}?&#62; 第二种方法： 同样是先修改css的文件名，把v2op.css 修改为 v2op.css.php。 然后在文件开头处加上下面这段代码（注意文件的编码，这里是utf-8，根据你自己的需要修改） &#60;?php ob_start ("ob_gzhandler"); header ("content-type: text/css; charset: UTF-8"); header ("cache-control: must-revalidate"); $offset = 60 &#8230; <a href="http://blog.v2op.com/2008/12/3-ways-to-compress-css-files-using-php/">Continue reading <span class="meta-nav">&#8594;</span></a><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fblog.v2op.com%2F2009%2F01%2F7-tips-for-the-best-imaging%2F&from=http%3A%2F%2Fblog.v2op.com%2F2008%2F12%2F3-ways-to-compress-css-files-using-php%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">如何发挥一只镜头的最佳成像</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fblog.v2op.com%2F2008%2F09%2Flink-visited-hover-active%2F&from=http%3A%2F%2Fblog.v2op.com%2F2008%2F12%2F3-ways-to-compress-css-files-using-php%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">超链接样式的正确顺序（link-visited-hover-active）</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fblog.v2op.com%2F2009%2F03%2Ftop-10-php-frameworks%2F&from=http%3A%2F%2Fblog.v2op.com%2F2008%2F12%2F3-ways-to-compress-css-files-using-php%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">10大PHP框架</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fblog.v2op.com%2F2010%2F08%2Fupload-large-files-in-php%2F&from=http%3A%2F%2Fblog.v2op.com%2F2008%2F12%2F3-ways-to-compress-css-files-using-php%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">PHP上传大文件时的参数设置</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>一个网站通常包含多个css文件。网站越复杂，这些css文件也会越庞大，对它们进行适当的压缩，可以节约不少带宽（在访问量巨大的时候尤为明显）。</p>
<p>下面介绍三种使用PHP压缩css的方法。</p>
<p><strong>第一种方法：</strong></p>
<p>修改css的文件名，比如把 v2op.css 改成 v2op.css.php。调用的方式如下：</p>
<pre>&lt;link rel="stylesheet" type="text/css" media="screen" href="/v2op.css.php"/&gt;

然后修改此v2op.css.php，在文件开头加上
&lt;?php
if(extension_loaded('zlib')){ob_start('ob_gzhandler');}
header("Content-type: text/css");
?&gt;

在文件最后面加上
&lt;?php if(extension_loaded('zlib')){ob_end_flush();}?&gt;

<strong>第二种方法：</strong>

同样是先修改css的文件名，把v2op.css 修改为 v2op.css.php。

然后在文件开头处加上下面这段代码（注意文件的编码，这里是utf-8，根据你自己的需要修改）
&lt;?php
   ob_start ("ob_gzhandler");
   header ("content-type: text/css; charset: UTF-8");
   header ("cache-control: must-revalidate");
   $offset = 60 * 60;
   $expire = "expires: " . gmdate ("D, d M Y H:i:s", time() + $offset) . " GMT";
   header ($expire);
?&gt;

<strong>第三种方法：</strong>

新建一个php文件，例如 v2op.css.php，然后include进来你的css文件，复制如下代码

&lt;?php
  header('Content-type: text/css');
  ob_start("compress");
  function compress($buffer) {
    /* remove comments */
    $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
    /* remove tabs, spaces, newlines, etc. */
    $buffer = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), '', $buffer);
    return $buffer;
  }

  /* 此处修改为你自己的css路径 */
  include('v2op.css');

  ob_end_flush();
?&gt;

我个人更喜欢这种方式 <img src='http://blog.v2op.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> 

当然，如果您嫌麻烦，也可以使用现成的工具去优化css，比如 <a href="http://www.v2op.com/tools/csstidy/?lang=zh" target="_blank">csstidy</a></pre>
<p style="margin:0;padding:0;height:1px;overflow:hidden;">
    <script type="text/javascript"><!--
        var wumiiSitePrefix = "http://blog.v2op.com";
        var wumiiEnableCustomPos = false;
        var wumiiParams = "&#038;num=4&#038;mode=3&#038;displayInFeed=1&#038;version=1.0.5.5&#038;pf=WordPress3.3.1";
    //--></script><script type="text/javascript" src="http://widget.wumii.com/ext/relatedItemsWidget.htm"></script><a href="http://www.wumii.com/widget/relatedItems.htm" style="border:0;"><img src="http://static.wumii.com/images/pixel.png" alt="无觅相关文章插件，快速提升流量" style="border:0;padding:0;margin:0;" /></a></p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fblog.v2op.com%2F2009%2F01%2F7-tips-for-the-best-imaging%2F&from=http%3A%2F%2Fblog.v2op.com%2F2008%2F12%2F3-ways-to-compress-css-files-using-php%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">如何发挥一只镜头的最佳成像</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fblog.v2op.com%2F2008%2F09%2Flink-visited-hover-active%2F&from=http%3A%2F%2Fblog.v2op.com%2F2008%2F12%2F3-ways-to-compress-css-files-using-php%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">超链接样式的正确顺序（link-visited-hover-active）</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fblog.v2op.com%2F2009%2F03%2Ftop-10-php-frameworks%2F&from=http%3A%2F%2Fblog.v2op.com%2F2008%2F12%2F3-ways-to-compress-css-files-using-php%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">10大PHP框架</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fblog.v2op.com%2F2010%2F08%2Fupload-large-files-in-php%2F&from=http%3A%2F%2Fblog.v2op.com%2F2008%2F12%2F3-ways-to-compress-css-files-using-php%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">PHP上传大文件时的参数设置</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://blog.v2op.com/2008/12/3-ways-to-compress-css-files-using-php/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

