<?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>SeoExploration &#187; Website Optimization</title> <atom:link href="http://www.seoexploration.com/tag/website-optimization/feed/" rel="self" type="application/rss+xml" /><link>http://www.seoexploration.com</link> <description>discovering new optimisation techniques</description> <lastBuildDate>Fri, 11 Nov 2011 14:37:05 +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>How To Optimize Your Site With GZIP Compression</title><link>http://www.seoexploration.com/2009/05/how-to-optimize-your-site-with-gzip-compression/</link> <comments>http://www.seoexploration.com/2009/05/how-to-optimize-your-site-with-gzip-compression/#comments</comments> <pubDate>Sat, 23 May 2009 14:17:40 +0000</pubDate> <dc:creator>anon</dc:creator> <category><![CDATA[Website Optimization]]></category> <category><![CDATA[bandwidth optimization]]></category><guid
isPermaLink="false">http://www.seoexploration.com/?p=15</guid> <description><![CDATA[Compression is a simple, effective way to save bandwidth and speed up your site. I hesitated when recommending gzip compression when speeding up your javascript because of problems in older browsers. But it’s 2007. Most of my traffic comes from modern browsers, and quite frankly, most of my users are fairly tech-savvy. I don’t want [...]]]></description> <content:encoded><![CDATA[<p
id="post-53" class="post-title">Compression is a simple, effective way to save bandwidth and speed up your site. I hesitated when recommending gzip compression when <a
title="speed-up-your-javascript" href="http://betterexplained.com/articles/speed-up-your-javascript-load-time/">speeding up your javascript</a> because of <a
title="problems in older browsers" onclick="javascript:urchinTracker ('/outbound/support.microsoft.com');" href="http://support.microsoft.com/kb/837251" target="_blank">problems</a> <a
onclick="javascript:urchinTracker ('/outbound/support.microsoft.com');" href="http://support.microsoft.com/kb/823386">in</a> <a
onclick="javascript:urchinTracker ('/outbound/schroepl.net');" href="http://schroepl.net/projekte/mod_gzip/browser.htm">older browsers</a>.</p><p>But it’s 2007. Most of my traffic comes from modern browsers, and quite frankly, most of <a
onclick="javascript:urchinTracker ('/outbound/instacalc.com');" href="http://instacalc.com/">my users</a> are fairly tech-savvy. I don’t want to slow everyone else down because somebody is chugging along on IE 4.0 on Windows 95. Google and Yahoo use gzip compression. A modern browser is needed to enjoy modern web content and modern web speed — so gzip encoding it is. Here’s how to set it up.</p><h2>Wait, wait, wait: Why are we doing this?</h2><p>Before we start I should explain what content encoding is. When you request a file like <code>http://www.yahoo.com/index.html</code>, your browser talks to a web server. The conversation goes a little like this:</p><p><a
href="http://www.seoexploration.com/wp-content/uploads/2009/05/http_request.png"><img
class="size-full wp-image-27 alignnone" style="border: 0pt none;" title="http_request" src="http://www.seoexploration.com/wp-content/uploads/2009/05/http_request.png" alt="http_request" width="437" height="221" /></a></p><p>1. Browser: Hey, <strong><span
class="caps">GET</span></strong> me /index.html<br
/> 2. Server: Ok, let me see if index.html is lying around…<br
/> 3. Server: Found it! Here’s your response code (200 OK) and I’m sending the file.<br
/> 4. Browser: 100KB? Ouch… waiting, waiting… ok, it’s loaded.</p><p>Of course, the actual headers and protocols are much more formal (monitor them with <a
href="http://betterexplained.com/articles/how-to-debug-web-applications-with-firefox/">Live <span
class="caps">HTTP</span> Headers</a> if you’re so inclined).</p><p>But it worked, and you got your file.</p><h2>So what’s the problem?</h2><p>Well, the system works, but it’s not that efficient. 100KB is a <strong>lot of text</strong>, and frankly, <span
class="caps">HTML </span>is redundant. Every <code>&lt;html&gt;, &lt;table&gt; and &lt;div&gt;</code> tag has a closing tag that’s almost the same. Words are repeated throughout the document. Any way you slice it, <span
class="caps">HTML </span>(and its beefy cousin, <span
class="caps">XML</span>) is not lean.</p><p>And what’s the plan when a file’s too big? Zip it!</p><p>If we could send a .zip file to the browser (index.html.zip) instead of plain old index.html, we’d save on bandwidth and download time. The browser could download the zipped file, extract it, and then show it to user, who’s in a good mood because the page loaded quickly. The browser-server conversation might look like this:</p><p><a
rel="attachment wp-att-29" href="http://www.seoexploration.com/2009/05/how-to-optimize-your-site-with-gzip-compression/http_request_compressed/"><img
class="size-full wp-image-29 alignnone" style="border: 0pt none;" title="http_request_compressed" src="http://www.seoexploration.com/wp-content/uploads/2009/05/http_request_compressed.png" alt="http_request_compressed" width="433" height="213" /></a></p><p>1. Browser: Hey, can I <strong><span
class="caps">GET</span></strong> index.html? I’ll take a compressed version if you’ve got it.<br
/> 2. Server: Let me find the file… yep, it’s here. And you’ll take a compressed version? Awesome.<br
/> 3. Server: Ok, I’ve found index.html (200 OK), am zipping it and sending it over.<br
/> 4. Browser: Great! It’s only 10KB. I’ll unzip it and show the user.</p><p>The formula is simple: Smaller file = faster download = <strong>happy user</strong>.</p><p>Don’t believe me? The <span
class="caps">HTML </span>portion of the yahoo home page goes from 101kb to 15kb after compression:</p><p><img
title="yahoo_compression.PNG" src="http://betterexplained.com/wp-content/uploads/compression/yahoo_compression.PNG" border="0" alt="yahoo_compression.PNG" width="391" height="50" /></p><h2>The (not so) hairy details</h2><p>The tricky part of this exchange is the browser and server knowing it’s ok to send a zipped file over. The agreement has two parts</p><ul><li>The <strong>browser sends a header</strong> telling the server it accepts compressed content (gzip and deflate are two compression schemes): <code>Accept-Encoding: gzip, deflate</code></li></ul><ul><li>The <strong>server sends a response</strong> if the content is actually compressed: <code>Content-Encoding: gzip</code></li></ul><p>If the server doesn’t send the content-encoding response header, it means the file is not compressed (the default on many servers). The “Accept-encoding” header is just a request by the browser, not a demand. If the server doesn’t want to send back compressed content, the browser has to make do with the heavy regular version.</p><h2>Setting up the server</h2><p>The “good news” is that we can’t control the browser. It either sends the <code>Accept-encoding: gzip, deflate</code> header or it doesn’t.</p><p>Our job is to configure the server so it returns zipped content if the browser can handle it, saving bandwidth for everyone (and giving us a happy user).</p><p>In Apache, <a
onclick="javascript:urchinTracker ('/outbound/httpd.apache.org');" href="http://httpd.apache.org/docs/2.0/mod/mod_deflate.html">enabling output compression</a> is fairly straightforward. Add the following to your .htaccess file:</p><pre><code>
# compress all text &amp; html:
AddOutputFilterByType DEFLATE text/html text/plain text/xml

# Or, compress certain file types by extension:
&lt;Files *.html&gt;
SetOutputFilter DEFLATE
&lt;/Files&gt;
</code></pre><p>Apache actually has two compression options:</p><ul><li><strong>mod_deflate</strong> is easier to set up and is standard.</li><li><strong>mod_gzip</strong> seems more powerful: you can pre-compress content.</li></ul><p>Deflate is quick and works, so I use it; use mod_gzip if that floats your boat. In either case, Apache checks if the browser sent the “Accept-encoding” header and returns the compressed or regular version of the file. However, some older browsers may have trouble (more below) and there are special directives you can add to correct this.</p><p>If you can’t change your .htaccess file, you can <a
onclick="javascript:urchinTracker ('/outbound/perishablepress.com');" href="http://perishablepress.com/press/2007/03/26/fast-effective-php-compression/">use <span
class="caps">PHP</span></a> to return compressed content. Give your <span
class="caps">HTML </span>file a .php extension and add this code to the top:</p><pre><code>
In PHP:
&lt;?php if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?&gt;
</code></pre><p>We check the “Accept-encoding” header and return a gzipped version of the file (otherwise the regular version). This is almost like building your own webserver (what fun!). But really, try to use Apache to compress your output if you can help it. You don’t want to monkey with your files.</p><h2>Verify Your Compression</h2><p>Once you’ve configured your server, check to make sure you’re actually serving up compressed content.</p><ul><li><strong>Online:</strong> Use the <a
onclick="javascript:urchinTracker ('/outbound/www.gidnetwork.com');" href="http://www.gidnetwork.com/tools/gzip-test.php">online gzip test</a> to check whether your page is compressed.</li><li><strong>In your browser:</strong> Use <a
onclick="javascript:urchinTracker ('/outbound/addons.mozilla.org');" href="https://addons.mozilla.org/en-US/firefox/addon/60">Web Developer Toolbar</a> &gt; Information &gt; View Document Size (like I did for Yahoo, above) to see whether the page is compressed.</li><li><strong>View the headers:</strong> Use <a
onclick="javascript:urchinTracker ('/outbound/addons.mozilla.org');" href="https://addons.mozilla.org/en-US/firefox/addon/3829">Live <span
class="caps">HTTP</span> Headers</a> to examine the response. Look for a line that says “Content-encoding: gzip”.</li></ul><p>Be prepared to marvel at the results. The <a
onclick="javascript:urchinTracker ('/outbound/instacalc.com');" href="http://instacalc.com/">instacalc homepage</a> shrunk from 36k to 10k, a 75% reduction in size.</p><h2>Try Some Examples</h2><p>I’ve set up some pages and a <a
onclick="javascript:urchinTracker ('/downloads/zip/compression-example.zip');" href="http://betterexplained.com/examples/compressed/compression-example.zip">downloadable example</a>:</p><ul><li><a
href="http://betterexplained.com/examples/compressed/index.html">index.html</a> &#8211; No explicit compression (on this server, I am using compression by default <img
class="wp-smiley" src="http://betterexplained.com/wp-includes/images/smilies/icon_smile.gif" alt=":)" /> ).</li><li><a
href="http://betterexplained.com/examples/compressed/index.htm">index.htm</a> &#8211; Explicitly compressed with Apache .htaccess using *.htm as a rule</li><li><a
href="http://betterexplained.com/examples/compressed/index.php">index.php</a> &#8211; Explicitly compressed using the <span
class="caps">PHP </span>header</li></ul><p>Feel free to download the files, put them on your server and tweak the settings.</p><h2>Caveats</h2><p>As exciting as it may appear, <span
class="caps">HTTP</span> Compression isn’t all fun and games. Here’s what to watch out for:</p><ul><li><strong>Older browsers</strong>: Yes, some browsers still may have trouble with compressed content (they say they can accept it, but really they can’t). If your site absolutely must work with Netscape 1.0 on Windows 95, you may not want to use <span
class="caps">HTTP</span> Compression. Apache mod_deflate <a
onclick="javascript:urchinTracker ('/outbound/httpd.apache.org');" href="http://httpd.apache.org/docs/2.0/mod/mod_deflate.html#recommended">has some rules</a> to avoid compression for older browsers.</li><li><strong>Already-compressed content</strong>: Most images, music and videos are already compressed. Don’t waste time compressing them again. In fact, you probably only need to compress the “big 3″ (HTML, <span
class="caps">CSS </span>and Javascript).</li><li><strong><span
class="caps">CPU</span>-load</strong>: Compressing content on-the-fly uses <span
class="caps">CPU </span>time and saves bandwidth. Usually this is a great tradeoff given the speed of compression. There are ways to pre-compress static content and send over the compressed versions. This requires more configuration; even if it’s not possible, compressing output may still be a net win. Using <span
class="caps">CPU </span>cycles for a faster user experience is well worth it, given the short attention spans on the web.</li></ul><p>Enabling compression is one of the fastest ways to improve your site’s performance. Go forth, set it up, and let your users enjoy the benefits.</p><p>This article was taken with thanks from&#8221; <a
title="Better Explained" href="http://betterexplained.com/" target="_blank">BetterExplained</a> <span
class="blogDescription">Learn Right, Not Rote.&#8221;<br
/> <a
title="how-to-optimize-your-site-with-gzip-compression" href="http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/" target="_blank">http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/</a> </span></p> ]]></content:encoded> <wfw:commentRss>http://www.seoexploration.com/2009/05/how-to-optimize-your-site-with-gzip-compression/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Served from: www.seoexploration.com @ 2012-02-05 12:57:04 by W3 Total Cache -->
