<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Compress CSS on the fly</title>
	<atom:link href="http://grupenet.com/2007/10/01/compress-css-on-the-fly/feed/" rel="self" type="application/rss+xml" />
	<link>http://grupenet.com/2007/10/01/compress-css-on-the-fly/</link>
	<description>Software tips and tricks</description>
	<lastBuildDate>Mon, 11 Jan 2010 18:28:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Mike</title>
		<link>http://grupenet.com/2007/10/01/compress-css-on-the-fly/comment-page-1/#comment-1290</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Wed, 28 Oct 2009 20:37:03 +0000</pubDate>
		<guid isPermaLink="false">http://grupenet.com/2007/10/01/compress-css-on-the-fly/#comment-1290</guid>
		<description>I recently built a mod_perl output filter which runs inside Apache. It intercepts requests for .css files and compresses them on the fly. It doesn&#039;t mess with any cache headers. See here:

&lt;a href=&quot;https://secure.grepular.com/blog/index.php/2009/10/28/compressing-css-on-the-fly/&quot; rel=&quot;nofollow&quot;&gt;Compressing CSS on the Fly&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>I recently built a mod_perl output filter which runs inside Apache. It intercepts requests for .css files and compresses them on the fly. It doesn&#8217;t mess with any cache headers. See here:</p>
<p><a href="https://secure.grepular.com/blog/index.php/2009/10/28/compressing-css-on-the-fly/" rel="nofollow">Compressing CSS on the Fly</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: KTB</title>
		<link>http://grupenet.com/2007/10/01/compress-css-on-the-fly/comment-page-1/#comment-1257</link>
		<dc:creator>KTB</dc:creator>
		<pubDate>Tue, 31 Mar 2009 20:31:16 +0000</pubDate>
		<guid isPermaLink="false">http://grupenet.com/2007/10/01/compress-css-on-the-fly/#comment-1257</guid>
		<description>Heres a even simpler method to save a huge amount of bandwith:

# A Week Expires header from askapache

Header set Cache-Control &quot;max-age=604800, public&quot;

# compress all files from :http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/

SetOutputFilter DEFLATE

#Etags From: http://httpd.apache.org/docs/2.2/mod/core.html#fileetag
FileETag MTime Size

I love this one^^</description>
		<content:encoded><![CDATA[<p>Heres a even simpler method to save a huge amount of bandwith:</p>
<p># A Week Expires header from askapache</p>
<p>Header set Cache-Control &#8220;max-age=604800, public&#8221;</p>
<p># compress all files from :http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/</p>
<p>SetOutputFilter DEFLATE</p>
<p>#Etags From: <a href="http://httpd.apache.org/docs/2.2/mod/core.html#fileetag" rel="nofollow">http://httpd.apache.org/docs/2.2/mod/core.html#fileetag</a><br />
FileETag MTime Size</p>
<p>I love this one^^</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mario</title>
		<link>http://grupenet.com/2007/10/01/compress-css-on-the-fly/comment-page-1/#comment-1198</link>
		<dc:creator>Mario</dc:creator>
		<pubDate>Thu, 30 Oct 2008 23:22:35 +0000</pubDate>
		<guid isPermaLink="false">http://grupenet.com/2007/10/01/compress-css-on-the-fly/#comment-1198</guid>
		<description>In my experience compressing the css does make it a little lighter, but if done dynamically it actually takes a little more time to get to the browser client because of the overhead removing the whitespace.

To make it cacheable you can configure your apache to add an expires header or do it by sending the header using PHP as passerby said.

I decided not to use ob_start method because it actually made it slower for the browser to get it (~110ms compressing vs. ~75ms natural) what i did do was to generate one whole big CSS file from several files to reduce the number of requests made to the server.

If you still want to compress your CSS dynamically I found a better function at http://php.oregonstate.edu/manual/en/function.php-strip-whitespace.php (look in the comments).</description>
		<content:encoded><![CDATA[<p>In my experience compressing the css does make it a little lighter, but if done dynamically it actually takes a little more time to get to the browser client because of the overhead removing the whitespace.</p>
<p>To make it cacheable you can configure your apache to add an expires header or do it by sending the header using PHP as passerby said.</p>
<p>I decided not to use ob_start method because it actually made it slower for the browser to get it (~110ms compressing vs. ~75ms natural) what i did do was to generate one whole big CSS file from several files to reduce the number of requests made to the server.</p>
<p>If you still want to compress your CSS dynamically I found a better function at <a href="http://php.oregonstate.edu/manual/en/function.php-strip-whitespace.php" rel="nofollow">http://php.oregonstate.edu/manual/en/function.php-strip-whitespace.php</a> (look in the comments).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Comprimiendo con PHP el código de tu hoja estilos CSS dinámicamente - elWebmaster.com</title>
		<link>http://grupenet.com/2007/10/01/compress-css-on-the-fly/comment-page-1/#comment-1139</link>
		<dc:creator>Comprimiendo con PHP el código de tu hoja estilos CSS dinámicamente - elWebmaster.com</dc:creator>
		<pubDate>Fri, 01 Aug 2008 17:40:00 +0000</pubDate>
		<guid isPermaLink="false">http://grupenet.com/2007/10/01/compress-css-on-the-fly/#comment-1139</guid>
		<description>[...] Fuente: GrupeNet [...]</description>
		<content:encoded><![CDATA[<p>[...] Fuente: GrupeNet [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: passerby</title>
		<link>http://grupenet.com/2007/10/01/compress-css-on-the-fly/comment-page-1/#comment-840</link>
		<dc:creator>passerby</dc:creator>
		<pubDate>Thu, 24 Jan 2008 04:54:16 +0000</pubDate>
		<guid isPermaLink="false">http://grupenet.com/2007/10/01/compress-css-on-the-fly/#comment-840</guid>
		<description>This is a great suggestion and works awesome. If you implement the PHP header expires function you can cache the css file for as long as you like.

$offset = 60 * 60 * 24 * 1;
header(&quot;Expires: &quot; . gmdate(&quot;D, d M Y H:i:s&quot;, time() + $offset) . &quot; GMT&quot;);

That would make the css file cached for about 2 days. You can adjust that as needed. Have a good day. :)</description>
		<content:encoded><![CDATA[<p>This is a great suggestion and works awesome. If you implement the PHP header expires function you can cache the css file for as long as you like.</p>
<p>$offset = 60 * 60 * 24 * 1;<br />
header(&#8220;Expires: &#8221; . gmdate(&#8220;D, d M Y H:i:s&#8221;, time() + $offset) . &#8221; GMT&#8221;);</p>
<p>That would make the css file cached for about 2 days. You can adjust that as needed. Have a good day. <img src='http://grupenet.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jared Schwager</title>
		<link>http://grupenet.com/2007/10/01/compress-css-on-the-fly/comment-page-1/#comment-783</link>
		<dc:creator>Jared Schwager</dc:creator>
		<pubDate>Wed, 21 Nov 2007 14:05:44 +0000</pubDate>
		<guid isPermaLink="false">http://grupenet.com/2007/10/01/compress-css-on-the-fly/#comment-783</guid>
		<description>Karol Krizka, I actually removed the code from my website after reading the &lt;a href=&quot;http://grupenet.com/2007/10/01/compress-css-on-the-fly/#comment-617&quot; rel=&quot;nofollow&quot;&gt;points that Rithiur made&lt;/a&gt;.

I may try my hand at making a script that will compress HTML also, but I&#039;m still learning about how to use regex in PHP. It can get quite confusing at times.</description>
		<content:encoded><![CDATA[<p>Karol Krizka, I actually removed the code from my website after reading the <a href="http://grupenet.com/2007/10/01/compress-css-on-the-fly/#comment-617" rel="nofollow">points that Rithiur made</a>.</p>
<p>I may try my hand at making a script that will compress HTML also, but I&#8217;m still learning about how to use regex in PHP. It can get quite confusing at times.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karol Krizka</title>
		<link>http://grupenet.com/2007/10/01/compress-css-on-the-fly/comment-page-1/#comment-782</link>
		<dc:creator>Karol Krizka</dc:creator>
		<pubDate>Tue, 20 Nov 2007 21:07:22 +0000</pubDate>
		<guid isPermaLink="false">http://grupenet.com/2007/10/01/compress-css-on-the-fly/#comment-782</guid>
		<description>Hmm, your example does not seem to work here. But nevertheless, it is a very good idea. Also implementing the changes that Rithiur recommended would be a good addition. Finally you should be able to compress your HTML code in a similar way, no? What do you think?</description>
		<content:encoded><![CDATA[<p>Hmm, your example does not seem to work here. But nevertheless, it is a very good idea. Also implementing the changes that Rithiur recommended would be a good addition. Finally you should be able to compress your HTML code in a similar way, no? What do you think?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jared Schwager</title>
		<link>http://grupenet.com/2007/10/01/compress-css-on-the-fly/comment-page-1/#comment-628</link>
		<dc:creator>Jared Schwager</dc:creator>
		<pubDate>Mon, 22 Oct 2007 16:23:52 +0000</pubDate>
		<guid isPermaLink="false">http://grupenet.com/2007/10/01/compress-css-on-the-fly/#comment-628</guid>
		<description>Rithiur, I can&#039;t believe I hadn&#039;t thought of that before. Great point! I&#039;ve definitely learned a couple new things today. I&#039;m somewhat new to PHP, so thanks for the pointers!</description>
		<content:encoded><![CDATA[<p>Rithiur, I can&#8217;t believe I hadn&#8217;t thought of that before. Great point! I&#8217;ve definitely learned a couple new things today. I&#8217;m somewhat new to PHP, so thanks for the pointers!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rithiur</title>
		<link>http://grupenet.com/2007/10/01/compress-css-on-the-fly/comment-page-1/#comment-617</link>
		<dc:creator>Rithiur</dc:creator>
		<pubDate>Sun, 21 Oct 2007 20:30:31 +0000</pubDate>
		<guid isPermaLink="false">http://grupenet.com/2007/10/01/compress-css-on-the-fly/#comment-617</guid>
		<description>Well done. You&#039;ve just successfully negated one of the primary reasons for using stylesheets: browser cache.

You see, one big advantage with CSS stylesheet files is that browser can cache them for a time, so that they do not need to be loaded on every page load. This gives nice performance boost, and saves plenty of bandwidth with bigger stylesheets. However, dynamic pages which are created with PHP can not be cached because the server can not determine the modification date for the file.

So, your compression script is actually causing significant increase in load due to increased bandwidth and processing required for the PHP file.

If you want to use something like this, you should rather use a separate script to &quot;build&quot; the CSS file from original copy and store that, rather than create a dynamic file. But without this kind of &quot;caching&quot;, the script completely backfires.

Also, three things about your code:

1. The regex is interesting. Sure, it works, but it would be considerably easier just to use ungreedy matching like &quot;!/\*.*\*/!Us&quot;
2. The str_replace doesn&#039;t display properly in the blog post. If you just copypaste from there, you end up removing all the whitespace in the CSS, which is not very good idea.
3. The compression logic is flawed. You can&#039;t just go around removing whitespace like that. Newlines are just as valid whitespace as space character. If you for example separate values of border-width with newlines, that &quot;compressor&quot; will end up removing the separating whitspace. Mostly safe method to remove whitespace would be replacing &quot;/\s+/&quot; with &quot; &quot; (single space), because multiple whitespace is rarely needed (only actually matters inside quoted values, which shouldn&#039;t be a problem).

But, as I said, one of the major advantages of CSS files is local caching, and thus compressing your CSS files is mostly just wasted effort.</description>
		<content:encoded><![CDATA[<p>Well done. You&#8217;ve just successfully negated one of the primary reasons for using stylesheets: browser cache.</p>
<p>You see, one big advantage with CSS stylesheet files is that browser can cache them for a time, so that they do not need to be loaded on every page load. This gives nice performance boost, and saves plenty of bandwidth with bigger stylesheets. However, dynamic pages which are created with PHP can not be cached because the server can not determine the modification date for the file.</p>
<p>So, your compression script is actually causing significant increase in load due to increased bandwidth and processing required for the PHP file.</p>
<p>If you want to use something like this, you should rather use a separate script to &#8220;build&#8221; the CSS file from original copy and store that, rather than create a dynamic file. But without this kind of &#8220;caching&#8221;, the script completely backfires.</p>
<p>Also, three things about your code:</p>
<p>1. The regex is interesting. Sure, it works, but it would be considerably easier just to use ungreedy matching like &#8220;!/\*.*\*/!Us&#8221;<br />
2. The str_replace doesn&#8217;t display properly in the blog post. If you just copypaste from there, you end up removing all the whitespace in the CSS, which is not very good idea.<br />
3. The compression logic is flawed. You can&#8217;t just go around removing whitespace like that. Newlines are just as valid whitespace as space character. If you for example separate values of border-width with newlines, that &#8220;compressor&#8221; will end up removing the separating whitspace. Mostly safe method to remove whitespace would be replacing &#8220;/\s+/&#8221; with &#8221; &#8221; (single space), because multiple whitespace is rarely needed (only actually matters inside quoted values, which shouldn&#8217;t be a problem).</p>
<p>But, as I said, one of the major advantages of CSS files is local caching, and thus compressing your CSS files is mostly just wasted effort.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jared Schwager</title>
		<link>http://grupenet.com/2007/10/01/compress-css-on-the-fly/comment-page-1/#comment-572</link>
		<dc:creator>Jared Schwager</dc:creator>
		<pubDate>Tue, 16 Oct 2007 22:25:58 +0000</pubDate>
		<guid isPermaLink="false">http://grupenet.com/2007/10/01/compress-css-on-the-fly/#comment-572</guid>
		<description>Chris, I was also thinking about that as I implemented this on my site. I&#039;m going to dig around the web to see how hard it might be to implement a cache system so the stylesheet wouldn&#039;t need to be processed every time it is loading.</description>
		<content:encoded><![CDATA[<p>Chris, I was also thinking about that as I implemented this on my site. I&#8217;m going to dig around the web to see how hard it might be to implement a cache system so the stylesheet wouldn&#8217;t need to be processed every time it is loading.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
