<?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>Sydney Web design blog &#124; Cheb 2.0 &#187; Wordpress</title>
	<atom:link href="http://www.cheb.com.au/category/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cheb.com.au</link>
	<description>A blog about Australia/Sydney Web design, Web 2.0, Technology, Gadgets, CSS/XHTML and more!</description>
	<lastBuildDate>Tue, 21 Jul 2009 01:46:31 +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>Making WordPress faster with Apache and PHP</title>
		<link>http://www.cheb.com.au/making-wordpress-faster-with-php-mod_gzip/</link>
		<comments>http://www.cheb.com.au/making-wordpress-faster-with-php-mod_gzip/#comments</comments>
		<pubDate>Sun, 02 Dec 2007 03:59:49 +0000</pubDate>
		<dc:creator>Cheb</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[optimisation]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.cheb.com.au/making-wordpress-faster-with-php-mod_gzip/</guid>
		<description><![CDATA[WordPress is one of the most popular (and my favourite) publishing solutions/blogging platforms/CMS systems online. It&#8217;s fast, reliable and best of all, free! There are however many ways to make sure you get the best out of WordPress and what it has to offer you in terms of the speed, power and throughput. Below is [...]]]></description>
			<content:encoded><![CDATA[<p><strong>WordPress is one of the most popular (and my favourite) publishing solutions/blogging platforms/CMS systems online. It&#8217;s fast, reliable and best of all, free!</strong></p>
<p><strong>There are however many ways to make sure you get the best out of <a title="Wordpress homepage" href="http://www.wordpress.org" target="_blank">WordPress</a> and what it has to offer you in terms of the speed, power and throughput.</strong></p>
<p>Below is part one in the series of code tweaks that will ensure that your copy of <a title="Wordpress category at Cheb 2.0" href="http://www.cheb.com.au/category/wordpress/">WordPress</a>; especially if running multiple CSS/JavaScript files and/or plugins &#8211; runs faster than ever before. <span id="more-24"></span></p>
<p>If you are running <a title="Apache Webserver" href="http://www.apache.org/" target="_blank">Apache webserver </a>with <a title="mod_gzip - Internet Content Acceleration Module" href="http://sourceforge.net/projects/mod-gzip/" target="_blank">mod_gzip</a> enabled, you can compress your files by up to 75% in order to make your page load faster, as well as reducing your HTTP requests. Let&#8217;s just try out making your main .CSS theme file smaller today&#8230;</p>
<p>The best way to do this it to follow the following steps.</p>
<p>1. Backup a copy of the main .CSS file(s) used on the blog. For this demonstration, I will assume the main CSS file for your theme is called &#8216;style.css&#8217;.</p>
<p>2. Copy the file &#8216;style.css&#8217; onto the web server so you don&#8217;t have to edit the original.</p>
<p>3. Rename the copied file to style.css.php &#8211; Yes, to .PHP (that means we are going to be scripting a little!)</p>
<p>4. Edit the file so that the following lines appear before any CSS. (I.e. if your first line of the CSS file has &#8216;body&#8217;, put a line break before &#8216;body&#8217; so now it is on line 2 of your document, and then paste the following onto line 1).</p>
<p>[sourcecode language='php']</p>
<p><?php</p>
<p>ob_start('ob_gzhandler');</p>
<p>header('Content-Type: text/css; charset: UTF-8');<br />
header('Cache-Control: must-revalidate');</p>
<p>$expire_offset_time = 604800; // Set to a reasonable interval. I.e. 3600 (sec.) = 1 hr.<br />
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expire_offset_time) . ' GMT');</p>
<p>?></p>
<p>[/sourcecode]</p>
<p>Let&#8217;s go through and explain some of the code for those that aren&#8217;t as technical with <a title="PHP.net" href="http://www.php.net" target="_blank">PHP</a>. Any definitions below are courtesy of PHP.net.</p>
<p><strong>Line 3:</strong></p>
<p><strong>ob_gzhandler()</strong> is intended to be used as a callback function for <a class="function" href="http://au2.php.net/manual/en/function.ob-start.php">ob_start()</a> to help facilitate sending gz-encoded data to web browsers that support compressed web pages. Before <strong>ob_gzhandler()</strong> actually sends compressed data, it determines what type of content encoding the browser will accept, and will return its output accordingly. All browsers are supported since it&#8217;s up to the browser to send the correct header saying that it accepts compressed web pages.</p>
<p>In English, basically, calling &#8220;ob_gzhandler()&#8221; effectively means that the contents of the page below that call are compressed by default through Apache.</p>
<p><strong>Line 5 &amp; 6:</strong></p>
<p>These two lines essentially setup the headers for the file (which will be asked for when a browser downloads the file) to tell the browser that the content in that particular file is CSS, and the character set being used is <a title="UTF-8 at Wikipedia" href="http://en.wikipedia.org/wiki/UTF-8" target="_blank">UTF-8</a> (character encoding for unicode). Secondly, line 6 sets up the Cache control of the the file. We are effectively saying that the browser should re-validate the contents of the time as opposed to, only-if-cached or max-age. The reason we apply the must-revalidate Cache control header is because a cache <em>may</em> be configured to ignore a server&#8217;s specified expiration time and so, we basically override this setting.</p>
<p><strong>Line 8 &amp; 9:</strong></p>
<p>Line 8 sets up a variable we create called expire_offset_time which will hold the value &#8217;604800&#8242; which at this stage is just a &#8216;number&#8217;, but will be used on the next line as an expiry interval. Line 9 in this case sets the contents of the page to expire after the variable we set above; which now represents seven (7) days worth of the content not expiring. The calculation for this is: ((604800 / 3600)/24) = 7; where 604800 is what we set; 3600 is the amount of seconds in one day, and 24 is the amount of hours in one day.</p>
<p>And there you have it. Adding the above to your CSS file, appending .php to the end of the filename, and obviously changing the link in your homepage template can mean big savings in load time and site speed. Based on my CSS file, the savings in KB&#8217;s are pretty substantial to say the least! My CSS file on the server has a footprint of 23KB. As you can see from the image below, the new file size is 5KB &#8211; close to a (whopping?) 5 times smaller!! I&#8217;ll let the &#8216;after&#8217; screen shot taken from <a title="Firebug for Firefox browser" href="http://www.getfirebug.com" target="_blank">Firebug</a> speak for itself!</p>
<p><img src="http://www.cheb.com.au/wp-content/uploads/2007/12/csssize.gif" alt="CSS size - PHP and mod_gzip" /></p>
<p><strong>So what do you think? Have you previously tried this method? Did it work for you? Share your thoughts with everyone! </strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cheb.com.au/making-wordpress-faster-with-php-mod_gzip/feed/</wfw:commentRss>
		<slash:comments>3894</slash:comments>
		</item>
	</channel>
</rss>

