<?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>Grupenet &#187; compression</title>
	<atom:link href="http://grupenet.com/tag/compression/feed/" rel="self" type="application/rss+xml" />
	<link>http://grupenet.com</link>
	<description>Software tips and tricks</description>
	<lastBuildDate>Thu, 24 Dec 2009 19:23:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Compress CSS on the fly</title>
		<link>http://grupenet.com/2007/10/01/compress-css-on-the-fly/</link>
		<comments>http://grupenet.com/2007/10/01/compress-css-on-the-fly/#comments</comments>
		<pubDate>Mon, 01 Oct 2007 16:08:03 +0000</pubDate>
		<dc:creator>Jared Schwager</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[compression]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://grupenet.com/2007/10/01/compress-css-on-the-fly/</guid>
		<description><![CDATA[In an attempt to further speed up loading times for Grupenet, I decided to compress (remove spaces and comments) my CSS stylesheet. However, instead of applying compression directly to the original file, why not add some PHP code to the stylesheet to compress the CSS dynamically when it is loaded on the server? This way [...]]]></description>
			<content:encoded><![CDATA[<p>In an attempt to further speed up loading times for Grupenet, I decided to compress (remove spaces and comments) my CSS stylesheet. However, instead of applying compression directly to the original file, why not add some PHP code to the stylesheet to compress the CSS dynamically when it is loaded on the server? This way all readability is maintained when editing the original file. This way you can add as much commenting as you need to keep your CSS more organized.</p>
<h3>Step 1</h3>
<p>Create a new file called <strong>.htaccess</strong> in the same directory your stylesheet is in. Open your newly created .htaccess file and add the following lines: </p>
<p><code>&lt;Files style.css&gt;<br />
SetHandler  application/x-httpd-php<br />
&lt;/Files&gt;</code></p>
<p>(Replace style.css with the filename of your stylesheet)</p>
<h3>Step 2</h3>
<p>Open up your stylesheet and <strong>add the following to the top of your stylesheet</strong>:</p>
<p><code>&lt;?php<br />
header('Content-type: text/css');<br />
function compress($buffer) {<br />
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);<br />
$buffer = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), '', $buffer);<br />
return $buffer;<br />
}<br />
ob_start("compress");<br />
?&gt;</code></p>
<p>Now <strong>add this to the bottom of your stylesheet</strong>:</p>
<p><code>&lt;?php ob_end_flush(); ?&gt;</code></p>
<h3>Step 3</h3>
<p>That's all there is to it! Now open up your browser and point it to your stylesheet. All the comments and spacing should be removed, and it should look something like <a href="http://grupenet.com/wp-content/themes/grupenet/style.css">this</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://grupenet.com/2007/10/01/compress-css-on-the-fly/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>
