<?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>Seifi.org &#187; performance</title>
	<atom:link href="http://www.seifi.org/category/performance/feed" rel="self" type="application/rss+xml" />
	<link>http://www.seifi.org</link>
	<description>A Web Development Blog by Joe Seifi - seifi.org</description>
	<lastBuildDate>Thu, 12 Aug 2010 05:35:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>YSlow Review, add-on for the firebug add-on</title>
		<link>http://www.seifi.org/performance/yslow-review-the-firebug-addon.html</link>
		<comments>http://www.seifi.org/performance/yslow-review-the-firebug-addon.html#comments</comments>
		<pubDate>Wed, 25 Jul 2007 19:29:29 +0000</pubDate>
		<dc:creator>Joe Seifi</dc:creator>
				<category><![CDATA[performance]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://www.seifi.org/performance/yslow-the-firebug-extension-extension.html</guid>
		<description><![CDATA[I&#8217;ve been playing around with YSlow, the&#160;add-on to the FireBug&#160;add-on&#160;which analyzes web pages and tells you why they&#8217;re slow based on the rules for high performance web sites, and assigns a letter grade. Basically all the sites I am running through it are getting a C grade so I decided to dig deeper. YSlow uses [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing around with <a href="http://developer.yahoo.com/yslow/">YSlow</a>, the&nbsp;<a href="https://addons.mozilla.org/en-US/firefox/addon/5369">add-on</a> to the <a href="http://www.seifi.org/firebug/firebug_tips_and_tricks.html">FireBug</a>&nbsp;<a href="http://www.getfirebug.com/">add-on</a>&nbsp;which analyzes web pages and tells you why they&#8217;re slow based on the <a href="http://developer.yahoo.com/performance/index.html#rules">rules for high performance web sites</a>, and assigns a letter grade. Basically all the sites I am running through it are getting a C grade so I decided to dig deeper. YSlow uses 13 points to come up with the grade. These rules are as follows:</p>
<p> <span id="more-586"></span>
<ol>
<li>Make fewer HTTP requests
<li>Use a CDN
<li>Add an Expires header
<li>Gzip components
<li>Put CSS at the top
<li>Move scripts to the bottom
<li>Avoid CSS expressions
<li>Make JS and CSS external
<li>Reduce DNS lookups
<li>Minify JS
<li>Avoid redirects
<li>Remove duplicate scripts
<li>Configure ETags</li>
</ol>
<p>My blog gets a&nbsp;C grade, ouch, but shouldn&#8217;t 79 really be C+ or B-?</p>
<p><img height="345" src="http://www.seifi.org/wp-content/uploads/2007/07/yslow-report-thumb1.gif" width="356" border="0"> </p>
<p><strong>So How are the grades computed?</strong> </p>
<p>This is from the <a href="http://developer.yahoo.com/yslow/help/">docs</a> for YSlow which outlines these rules and give you more tips on what to do to improve your grade.</p>
<blockquote><p>The grades for individual rules are computed differently depending on the rule. For example, for Rule 1, <u>three external scripts are allowed</u>. For each script above that, four points are deducted from the grade. The code for grading each rule is found in <u>lint.js</u>. The overall grade is a weighted average of the individual grades for each rule. The rules are <u>approximately in order of importance</u>, most important first. The specific weights are in the lintweights array in <u>yslowcontext.js</u>.</p>
</blockquote>
<p><p>Here is the specific array mentioed above with the weights assigned to each rule:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">lintweights</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #3366CC;">&quot;NumComps&quot;</span>     <span style="color: #339933;">:</span> <span style="color: #CC0000;">8</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;CDN&quot;</span>          <span style="color: #339933;">:</span> <span style="color: #CC0000;">6</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;Expires&quot;</span>      <span style="color: #339933;">:</span> <span style="color: #CC0000;">10</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;Gzip&quot;</span>         <span style="color: #339933;">:</span> <span style="color: #CC0000;">8</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;CssAtTop&quot;</span>     <span style="color: #339933;">:</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;JsAtBottom&quot;</span>   <span style="color: #339933;">:</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;Expression&quot;</span>   <span style="color: #339933;">:</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;ExternalFiles&quot;</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;Domains&quot;</span>      <span style="color: #339933;">:</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;Obfuscate&quot;</span>    <span style="color: #339933;">:</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;Redirects&quot;</span>    <span style="color: #339933;">:</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;JsTwice&quot;</span>      <span style="color: #339933;">:</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;ETags&quot;</span>        <span style="color: #339933;">:</span> <span style="color: #CC0000;">2</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

</p>
<p>Let&#8217;s look at why I got some the grades.</p>
<h3>Rule #2 Use a CDN</h3>
<p>I got a letter of F in rule 2&nbsp;for not using a CDN.&nbsp;Is Yahoo getting paid to promote <a href="http://www.akamai.com/">Akamai</a>? No but seriously, I doubt any personal blogs are going to start using professional CDNs anytime soon, not unless they are super successful. But if you are using your own personal image cache servers you should add your server host to&nbsp;the list of &#8220;known CDNs&#8221;, because the default CDNs are the ones used by Yahoo! and chances are these are not relevant to your web site. Here&#8217;s how to add them according to the YSlow docs.</p>
<ol>
<ol>
<li>Go to <code>about:config</code> in Firefox. You&#8217;ll see the current list of preferences.
<li>Right-click in the window and choose New and String to create a new string preference.
<li>Enter <code>extensions.firebug.yslow.cdnHostnames</code> for the preference name.
<li>For the string value, enter the hostname of your CDN, for example, <code>mycdn.com</code>. Do not use quotes. If you have multiple CDN hostnames, separate them with commas. </li>
</ol>
</ol>
<h3>Rule #3 Add an Expires header </h3>
<p>This rule suggests adding Expires tags using the Apache server setttings. According to research at Yahoo they have come up with the <a href="http://yuiblog.com/blog/2006/11/28/performance-research-part-1/">80/20 rule</a> of reducing HTTP traffic.</p>
<blockquote><p>Since browsers spend 80% of the time fetching external components including scripts, stylesheets and images, reducing the number of HTTP requests has the biggest impact on reducing response time.</p>
</blockquote>
<p>These are the complaints YSlow has for my Expires tags. </p>
<ul style="color:#f00;font-size:11px;list-style-type:none;margin:0;padding:0;">These components do not have a far future Expires header:
<li><img title="HTTP headers" height="10" src="http://us.i1.yimg.com/us.yimg.com/i/rt/yslow/magnify.gif" width="11" border="0">&nbsp;(7/26/2007) http://pagead2.googlesyndication.com/pagead/show_ads.js
<li><img title="HTTP headers" height="10" src="http://us.i1.yimg.com/us.yimg.com/i/rt/yslow/magnify.gif" width="11" border="0">&nbsp;(no expires) http://stats.wordpress.com/e-200730.js
<li><img title="HTTP headers" height="10" src="http://us.i1.yimg.com/us.yimg.com/i/rt/yslow/magnify.gif" width="11" border="0">&nbsp;(7/26/2007) http://edge.quantserve.com/quant.js</li>
</ul>
<p></p>
<p>Here are the docs for using <a href="http://httpd.apache.org/docs/1.3/mod/mod_expires.html">mod_expires</a>.&nbsp; In this environment you can turn on this expires setting in your .htaccess file using these directives:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;</span>IfModule mod_expires.c<span style="color: #000000; font-weight: bold;">&gt;</span>
ExpiresActive on
ExpiresByType image<span style="color: #000000; font-weight: bold;">/</span>gif <span style="color: #ff0000;">&quot;access plus 1 month&quot;</span>
ExpiresByType image<span style="color: #000000; font-weight: bold;">/</span>jpeg <span style="color: #ff0000;">&quot;access plus 1 month&quot;</span>
ExpiresByType image<span style="color: #000000; font-weight: bold;">/</span>png <span style="color: #ff0000;">&quot;access plus 1 month&quot;</span>
ExpiresByType text<span style="color: #000000; font-weight: bold;">/</span>css <span style="color: #ff0000;">&quot;access plus 1 month&quot;</span>
ExpiresByType application<span style="color: #000000; font-weight: bold;">/</span>x-javascript <span style="color: #ff0000;">&quot;access plus 1 month&quot;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>IfModule<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>I&#8217;m using 1 month expiration dates, but Yahoo is suggesting 10 years. You might want to pick something that suits your specific needs. By its nature having the expires tag should in turn reduce your browser&#8217;s HTTP requests, thereby improving your score on Rule #1 of&nbsp;Making fewer HTTP requests.</p>
<h3>Rule #13 Configure ETags</h3>
<p>Another point to touch up on is the Etags required in Rule #13. YSlow is complaining about Etags because of a known problem with the way Etags are <a href="http://david.weekly.org/writings/etags.php3">written</a> if you have a clustered server network. If your site is served off of one server this ETags score is pretty much useless. Etags is basically a string that <a href="http://httpd.apache.org/docs/1.3/mod/core.html#fileetag">Apache</a> slaps on as a response header. By default this string is composed of 3 parts. </p>
<ol>
<li>The file&#8217;s last modification date
<li>its current size
<li>its Unix inode</li>
</ol>
<p>The problem is that with multiple server environments, your inodes are going to be unique and different for each server. So if you have a banner.gif on 12 servers, it will have 12 different Etags, therefore making the whole thing useless. YSlow suggests to remove Etags all together using the directive :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">FileETag none</pre></div></div>

<p>This seems to be the norm for most big portals such as Google and Yahoo these days. This way you not only reduce the complexity, but also reduce the HTTP response headers flying around. If you really want to use Etags you can remove the inode from the Etags string by using this directive which will only use the modified time and size of the file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">FileETag MTime Size</pre></div></div>

<p>So in my case I have 3 files that have Etags that I have no control over, since they are external stats files and I would think that eventually these people would use YSlow and fix their FileEtag directives accordingly.</p>
<ul style="color:#f00;font-size:11px;list-style-type:none;margin:0;padding:0;">These components have an ETag:
<li><img title="HTTP headers" height="10" src="http://us.i1.yimg.com/us.yimg.com/i/rt/yslow/magnify.gif" width="11" border="0"> http://edge.quantserve.com/quant.js</li>
<li><img title="HTTP headers" height="10" src="http://us.i1.yimg.com/us.yimg.com/i/rt/yslow/magnify.gif" width="11" border="0"> http://stats.wordpress.com/e-200730.js</li>
</ul>
<h3>Rule # 12. Remove duplicate scripts</h3>
<p>YSlow noticed that the <a href="http://pagead2.googlesyndication.com/pagead/show_ads.js">show_ads.js</a> from Google&#8217;s AdSense program is loaded twice on this page. I&#8217;m currently using the terrific WordPress plugin <a href="http://www.mutube.com/projects/wordpress/adsense-manager/">AdSense Manager</a> which interestingly enough seems to be putting in the JS tag once for each ad on the page. I&#8217;m not sure if this is something that might be required by Google. I would be interested in finding out if I can change the plugin to include the AdSense script file only once which would make more &#8220;sense&#8221; without leading to potential side effects on Google&#8217;s side of things.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.seifi.org/performance/yslow-review-the-firebug-addon.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to Boost Your JavaScript and CSS Performance</title>
		<link>http://www.seifi.org/css/how_to_boost_your_javascript_and_css_performance.html</link>
		<comments>http://www.seifi.org/css/how_to_boost_your_javascript_and_css_performance.html#comments</comments>
		<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate>
		<dc:creator>Joe Seifi</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.seifi.org/css/how_to_boost_your_javascript_and_css_performance.html</guid>
		<description><![CDATA[Lines of markup code per website are growing at a hurried pace these days. JavaScript and CSS files are getting bigger by the day. But you want to keep your site lean and speedy and avoid from becoming slow and bloated. There are some basic techniques I use to optimize JavaScript files and the same [...]]]></description>
			<content:encoded><![CDATA[<p>Lines of markup code per website are growing at a hurried pace these days. JavaScript and CSS files are getting bigger by the day. But you want to keep your site lean and speedy and avoid from becoming slow and bloated. There are some basic techniques I use to optimize JavaScript files and the same ideas can be applied to CSS and HTML files as well. I&#8217;ll briefly cover 4 popular solutions, namely validating, joining, shrinking and compressing your markup source code.<span id="more-482"></span></p>
<h3><strong>1) Validate your code</strong></h3>
<p>Although JavaScript can be very forgiving when it comes to error handling, sloppy coding will come back to haunt you in the long run. So the first step is to validate your code. I use <a href="http://www.jslint.com/lint.html">JSLint</a> which scans JavaScript code for syntax errors and common mistakes and recommends fixes. JSLint piggy backs on <a href="http://www.mozilla.org/rhino/">Rhino</a> which is an implementation of JavaScript written in Java from <a href="http://www.mozilla.org/">Mozilla</a>. You can either use the <a href="http://www.jslint.com/">online version</a> or download and run the scanner locally. I prefer this local method which utilizes the <a href="http://www.java.com/">java runtime</a>.</p>
<p>To use <strong>JSLint</strong> locally:</p>
<ol>
<li>Download and unzip <a href="http://www.mozilla.org/rhino/download.html">Rhino</a> to a folder on your computer. You need <em>js.jar</em></li>
<li>Download and save the JSLint library file <a href="http://www.jslint.com/rhino/jslint.js"><em>jslint.js</em></a></li>
<li>Run JSLint in the Rhino Shell passing it a JavaScript file to scan. Here is the command I use assuming <em>js.jar</em>, <em>jslint.js</em>, and <em>MYBIG.js</em> are all in the same directory.</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">java <span style="color: #660033;">-classpath</span> js.jar 
org.mozilla.javascript.tools.shell.Main 
jslint.js MYBIG.js</pre></div></div>

<p>You will then see a list of errors found by JSLint and suggestions for fixing your code. Some of the most common items are:</p>
<ul>
<li>Missing end of line semi-colon delimiters <font color="#800080">;</font><strong> </strong></li>
<li>Not using <em>dot notation</em> to reference DOM objects (ex. <font color="#800080">form['name'].input.value <font color="#000000">instead of</font> form.name.input.value</font> )</li>
<li>Using <font color="#800080">==</font> instead of <font color="#800080">===</font> for comparing with null, undefined, booleans, zero and &#8220;&#8221;</li>
<li>Variable scope issues caused by declaring variables inside of loops instead of declaring them first in functions definitions.</li>
<li>Not using curly braces in your conditional blocks. So make a point to always do <font color="#800080">If(x){doX();}else{doY();}</font> even if you have one liners.</li>
<li>Stay away from using <font color="#800080"><strike>eval()</strike></font> or <font color="#800080"><strike>with().</strike></font><font color="#000000"> eval is evil <img src='http://www.seifi.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </font></li>
<li>Create your arrays using literal notation <font color="#800080">[]</font> instead of <font color="#800080"><strike>new Array()</strike></font></li>
<li>Create your objects using <font color="#800080">{}</font> instead of <font color="#800080"><strike>new Object()</strike></font></li>
<li>Avoid using <font color="#800080"><strike>javascript:function()</strike></font> in URLs</li>
<li>You can read more suggestions in the JSLint <a href="http://www.jslint.com/lint.html">docs</a>.</li>
</ul>
<h3><strong>2) Join your files</strong></h3>
<p>If you have five separate CSS files and three different JavaScript files, your server has to answer 8 HTTP requests per client. Each request requires additional processing and slows down your page loading. By concatenating your CSS and JavaScript files to only 2, you should see page load time improvements, especially when client requests are coming from distant networks.</p>
<p>Another tip that I have seen is to move your JavaScript include tags to the very bottom of the page, right before the &lt;/body&gt; tag. This will allow the browser to draw the DOM before loading your library files and the page will appear to load faster.</p>
<p>So after your various source files are nice and lint free, and combined into a single library file you are ready to start shrinking.</p>
<h3><strong>3) Shrink your library</strong></h3>
<p>Before shipping your code, shrink it. JavaScript and CSS files are not compiled and they contain lots of wasted whitespace which are nice to have when you&#8217;re coding but serve no benefit to the user of your website. There are four different tools you can use to filter out the unnecessary bits from your JavaScript and CSS files, and for the most part they are doing the same thing. I personally use ShrinkSafe which is a happy safe medium. The reason is that this tool does not mangle your code so that its API will stay in tact. If you choose to use a decryption based method to obfuscate your code, it can have harmful side effects. First, the size of the encrypted file can in some cases actually be larger than the original! Second, your scripted API can get mangled, forcing you to update all external pointers to your code. If you have any clients who use your API via JavaScript, you should obviously take great caution in using encryption methods.</p>
<blockquote><p><u>Caution:</u> As always, backup your code before making changes to them using these tools! There is no undo!</p></blockquote>
<h4><strong>JavaScript Shrinking</strong></h4>
<ol>
<li><a href="http://javascript.crockford.com/jsmin.html">JSMin</a> removes extra white-space and comments. It also reduces the line count by increasing the maximum line width. The result a bit uglier and harder to read and debug but also a bit smaller. Unlike ShrinkSafe, though JSMin does not edit your function arguments. You can <a href="http://javascript.crockford.com/jsmin.html">download</a> it in a variety of flavors. Here is a DOS executable version and the command to run it.

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">jsmin <span style="color: #000000; font-weight: bold;">&lt;</span>big.jsb <span style="color: #000000; font-weight: bold;">&gt;</span>min_jsmin.js <span style="color: #ff0000;">&quot;(c)2007 CORP&quot;</span></pre></div></div>

</li>
<li><a href="http://alex.dojotoolkit.org/shrinksafe/">ShrinkSafe</a> removes extra white-space and comments, but keeps one statement per line which is easy on the eye if you decide to edit your shrunk file. It also shrinks function arguments by replacing them with consecutive _## values which tends to reduce the files size some more. Download the jar file <a href="http://svn.dojotoolkit.org/dojo/trunk/buildscripts/lib/custom_rhino.jar">here</a> and run it as follows:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">java <span style="color: #660033;">-jar</span> custom_rhino.jar <span style="color: #660033;">-c</span> big.js <span style="color: #000000; font-weight: bold;">&gt;</span> 
min_shrinksafe.js <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span></pre></div></div>

</li>
<li><a href="http://dean.edwards.name/packer/">Packer</a> has a few options you can choose to minify your scripts. The normal option removes extra white-space and puts the entire file in one super long line. You can also choose to shrink  function as well as encode your script using a base62 algorithm. You can <a target="_blank" href="http://dean.edwards.name/packer/">try it</a> online. Although your file size is considerably smaller, depending on the complexity and cleanliness of your code (see JSLint above) using the two options in Packer might introduce errors with your code. In my case I had no problems with them.</li>
<li><a href="http://hometown.aol.de/_ht_a/memtronic/">MemTronic</a> &#8211; Hardcore shrinkers out there can try this online tool which produces the smallest file size in my tests. Be warned that this is only for the braveheart coders, has some known issues and may have some side effects.</li>
</ol>
<p>I have run Prototype.js against these 4 tools and the results are shown below. The results show that you can save at least 20% on your file size without compromising much stability.</p>
<table border="0" width="90%" cellPadding="0" cellSpacing="1" class="gridtable">
<tr>
<th>Tool Used</th>
<th>File Name</th>
<th>File Size</th>
<th>Lines</th>
<th>Reduced</th>
</tr>
<tr>
<td>None</td>
<td><a href="http://seifi.org/wp-content/uploads/2007/04/prototype.js">prototype.js</a></td>
<td>71,260</td>
<td>2514</td>
<td>Original</td>
</tr>
<tr>
<td>JSMin</td>
<td><a href="http://seifi.org/wp-content/uploads/2007/04/min_jsmin.js">min_jsmin.js</a></td>
<td>54,035</td>
<td>183</td>
<td>-24%</td>
</tr>
<tr>
<td>Shrinksafe</td>
<td><a href="http://seifi.org/wp-content/uploads/2007/04/min_shrinksafe.js">min_shrinksafe.js</a></td>
<td>50,725</td>
<td>1972</td>
<td>-29%</td>
</tr>
<tr>
<td>Packer</td>
<td><a href="http://seifi.org/wp-content/uploads/2007/04/min_packer_noptions.js">min_packer_noptions.js</a></td>
<td>53,455</td>
<td>1</td>
<td>-25%</td>
</tr>
<tr>
<td>Packer</td>
<td><a href="http://seifi.org/wp-content/uploads/2007/04/min_packer_shrunkvars.js">min_packer_shrunkvars.js</a></td>
<td>43,903</td>
<td>1</td>
<td>-38%</td>
</tr>
<tr>
<td>Packer</td>
<td><a href="http://seifi.org/wp-content/uploads/2007/04/min_packer_encoded.js">min_packer_encoded.js</a></td>
<td>29,273</td>
<td>1</td>
<td>-59%</td>
</tr>
<tr>
<td>Packer</td>
<td><a href="http://seifi.org/wp-content/uploads/2007/04/min_packer_both.js">min_packer_both.js</a></td>
<td>27,634</td>
<td>1</td>
<td>-61%</td>
</tr>
<tr>
<td>MemTronic</td>
<td><a href="http://seifi.org/wp-content/uploads/2007/04/min_memtronic_compress.js">min_memtronic_compress.js</a></td>
<td>24,483</td>
<td>1</td>
<td>-66%</td>
</tr>
</table>
<h4><strong><strong>CSS Shrinking</strong></strong></h4>
<ol>
<li><a href="http://www.cleancss.com/">Clean CSS</a> &#8211; This tool creates the best results, reducing the files size while maintaining a nicely formatted and readable CSS file. It has a plethora of options to choose from as well. For example, you can sort the properties of all the selectors which is a godsend for neat-freaks like me. It will also compress your css by converting possible properties to use shorthand notations. You can choose to save your comments.</li>
<li><a href="http://www.cssoptimiser.com/">CSS Optimiser</a> &#8211; This tool only has one option which is to remove line breaks or not. Does a good job however the final file size does not decrease much if you don&#8217;t pick that option, which makes the css tough to read.</li>
<li><a href="http://iceyboard.no-ip.org/projects/css_compressor">Icey CSS Compressor</a> &#8211;  Here is another powerful tool with lots of options to go around. Here are a few of them: Convert colors to hex, combine identical rules, combine properties, combine selectors, remove useless padding and margin. It also outputs in a nice colorful format for you. However there is no option to keep line breaks in tact so you get the output all in one line, and in my case this actually created an error.</li>
<li><a href="http://flumpcakes.co.uk/css/optimiser/">Flumpcakes Optimiser</a> &#8211; This tool has a few useful options such as combining backgrounds, fonts, lists, borders, and style which appear in multiple places. It can also convert RGB to hex and absolute to relative.</li>
</ol>
<p>I ran the CSS from <a href="http://reader.earthlink.net/">EarthLink ReaDeR</a> through the top four tools and the results are shown below.</p>
<table border="0" width="90%" cellPadding="0" cellSpacing="1" class="gridtable">
<tr>
<th>Tool Used</th>
<th>File Name</th>
<th>File Size</th>
<th>Lines</th>
<th>Reduced</th>
</tr>
<tr>
<td>None</td>
<td><a href="http://seifi.org/wp-content/uploads/2007/04/reader.css">reader.css</a></td>
<td>12,875</td>
<td>227</td>
<td>Original</td>
</tr>
<tr>
<td>Clean CSS</td>
<td><a href="http://seifi.org/wp-content/uploads/2007/04/min_cleancss.css">min_cleancss.css</a></td>
<td>11,735</td>
<td>940</td>
<td>-2%</td>
</tr>
<tr>
<td>CSS Optimiser</td>
<td><a href="http://seifi.org/wp-content/uploads/2007/04/min_cssoptimiser.css">min_cssoptimiser.css</a></td>
<td>11,304</td>
<td>2</td>
<td>-2%</td>
</tr>
<tr>
<td>Icey CSS Compressor</td>
<td><a href="http://seifi.org/wp-content/uploads/2007/04/min_icey.css">min_icey.css</a></td>
<td>10,383</td>
<td>1</td>
<td>-3%</td>
</tr>
<tr>
<td>Flumpcakes Optimisor</td>
<td><a href="http://seifi.org/wp-content/uploads/2007/04/min_flumpcakes.css">min_flumpcakes.css</a></td>
<td>12,885</td>
<td>796</td>
<td>0%</td>
</tr>
</table>
<p><!--adsense#post--></p>
<h3><strong>4) Compress your files</strong></h3>
<p>The HTTP implementation covers accept-encoding and content-encoding in detail and most browsers today support these methods. Basically when a browser sends a request, it tells the server it would like to have the file back in a compressed format such as gzip or deflate. The server then compresses the file and sends it back, and the browser decompresses the file and renders it in the browser. The most common format used today is GZip. Here is how to setup GZip in two popular web servers.</p>
<ol>
<li><strong>Apache &amp; mod_gzip</strong> &#8211; If you are running on Apache and have already compiled it with mod_gzip you can easily <a href="http://www.schroepl.net/projekte/mod_gzip/config.htm">configure</a> gzip compression by adding these lines to an .htaccess file placed in your web root or your http.conf file.

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mod_gzip_on Yes
mod_gzip_item_include <span style="color: #c20cb9; font-weight: bold;">file</span> \.php$
mod_gzip_item_include <span style="color: #c20cb9; font-weight: bold;">file</span> \.html$
mod_gzip_item_include mime ^text<span style="color: #000000; font-weight: bold;">/</span>html$
mod_gzip_item_include <span style="color: #c20cb9; font-weight: bold;">file</span> \.txt$
mod_gzip_item_include mime ^text<span style="color: #000000; font-weight: bold;">/</span>plain$
mod_gzip_item_include <span style="color: #c20cb9; font-weight: bold;">file</span> \.css$
mod_gzip_item_include mime ^text<span style="color: #000000; font-weight: bold;">/</span>css$
mod_gzip_item_include <span style="color: #c20cb9; font-weight: bold;">file</span> \.js$
mod_gzip_item_include mime ^application<span style="color: #000000; font-weight: bold;">/</span>x-javascript$
mod_gzip_item_exclude mime ^image<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>If you don&#8217;t have access to your .htaccess file but do have php compiled with the <a href="http://us2.php.net/manual/en/ref.zlib.php">zlib</a> module you can rename your javascript files to .php extensions and add this to the top of your file.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ob_gzhandler&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: text/javascript;charset:UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cache-Control: must-revalidate&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$offset</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">60</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">60</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">24</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">365</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// one year</span>
<span style="color: #000088;">$ExpStr</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Expires: &quot;</span> <span style="color: #339933;">.</span>
<span style="color: #990000;">gmdate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;D, d M Y H:i:s&quot;</span><span style="color: #339933;">,</span>
<span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$offset</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; GMT&quot;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ExpStr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

</li>
<li><strong>JBoss and Tomcat</strong> &#8211; To enable compression in a J2EE environment running Tomcat within <a href="http://www.jboss.com/">JBoss</a>, you can now enable compression by editing your server.xml that sits in the tomcat.sar folder. Just add these attributes to the Connector node:

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connector</span> <span style="color: #000066;">port</span>=<span style="color: #ff0000;">&quot;8080&quot;</span> <span style="color: #000066;">compression</span>=<span style="color: #ff0000;">&quot;on&quot;</span> </span>
<span style="color: #009900;"><span style="color: #000066;">compressionMinSize</span>=<span style="color: #ff0000;">&quot;300&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">noCompressionUserAgents</span>=<span style="color: #ff0000;">&quot;gozilla, traviata&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">compressableMimeType</span>=<span style="color: #ff0000;">&quot;text/html,text/xml,text/css,</span>
<span style="color: #009900;">text/javascript, application/x-javascript,</span>
<span style="color: #009900;">application/javascript&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

</li>
</ol>
<h3><strong>The Results</strong></h3>
<p>Finally, here are two pages that use the compressed versions of prototype.js and reader.css, one <a href="http://seifi.org/wp-content/uploads/2007/04/gzipped/index.php">with gzip compression enabled</a>, and the other <a href="http://seifi.org/wp-content/uploads/2007/04/nogzip/index.php">without gzip compression</a> enabled. Using the Net tab in <a href="http://www.seifi.org/node/477">FireBug</a> we can easily see that the gzipped version of both the CSS and JavaScript files actually result in less network traffic and faster loads times.</p>
<p>We cut our total throughput by 44 KB or 70%! Also the total load time is cut by 521ms or 51%, basically reduced from 1 second to half a second. If we do some quick math, for a website that gets 1,000,000 unique visitors per day, this is a daily savings of 44GB of bandwidth, and a total of about 145 precious hours saved.</p>
<table border="0" width="90%" cellPadding="0" cellSpacing="1" class="gridtable">
<tr>
<th>Size in KB</th>
<th>CSS</th>
<th>JavaScript</th>
<th>Total</th>
</tr>
<tr>
<td>No Compression</td>
<td>12KB</td>
<td>51KB</td>
<td>63KB</td>
</tr>
<tr>
<td>Gzipped</td>
<td>4KB</td>
<td>15KB</td>
<td>19KB</td>
</tr>
<tr>
<td>Reduction</td>
<td>8KB 67%</td>
<td>36KB 71%</td>
<td>44KB 70%</td>
</tr>
<tr>
<td colSpan="3">Savings for 1 mil uniques/day</td>
<td>44 GB</td>
</tr>
<tr>
<td colSpan="4" style="padding: 0px"><a href="http://seifi.org/wp-content/uploads/2007/04/nogzip/index.php"><img border="0" width="392" src="http://seifi.org/wp-content/uploads/2007/04/nogzip.gif" height="116" /></a></td>
</tr>
</table>
<p>
<p>&nbsp;</p>
<table border="0" width="90%" cellPadding="0" cellSpacing="1" class="gridtable">
<tr>
<th>Time in Milliseconds</th>
<th>CSS</th>
<th>JavaScript</th>
<th>Total</th>
</tr>
<tr>
<td>No Compression</td>
<td>281ms</td>
<td>741ms</td>
<td>1022ms</td>
</tr>
<tr>
<td>Gzipped</td>
<td>110</td>
<td>391</td>
<td>501ms</td>
</tr>
<tr>
<td>Reduction</td>
<td>171ms 61%</td>
<td>350ms 47%</td>
<td>521ms 51%</td>
</tr>
<tr>
<td colSpan="3">Savings for 1 mil uniques/day</td>
<td>145 Hrs.</td>
</tr>
<tr>
<td colSpan="4" style="padding: 0px"><a href="http://seifi.org/wp-content/uploads/2007/04/gzipped/index.php"><img border="0" width="392" src="http://seifi.org/wp-content/uploads/2007/04/gzipped.gif" height="116" /></a></td>
</tr>
</table>
<p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.seifi.org/css/how_to_boost_your_javascript_and_css_performance.html/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 1.706 seconds -->
<!-- Cached page served by WP-Cache -->
