<?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>Learning the World &#187; JSMin</title>
	<atom:link href="http://learningtheworld.eu/tag/jsmin/feed/" rel="self" type="application/rss+xml" />
	<link>http://learningtheworld.eu</link>
	<description></description>
	<lastBuildDate>Tue, 06 Nov 2012 00:17:33 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.9.1</generator>
	<item>
		<title>Website Performance Tweaks</title>
		<link>http://learningtheworld.eu/2007/performance/</link>
		<comments>http://learningtheworld.eu/2007/performance/#comments</comments>
		<pubDate>Thu, 25 Jan 2007 20:00:35 +0000</pubDate>
		<dc:creator><![CDATA[Martin Kliehm]]></dc:creator>
				<category><![CDATA[downloads]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[book:isbn=0596529309]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[concat]]></category>
		<category><![CDATA[css sprites]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Douglas Crockford]]></category>
		<category><![CDATA[Ed Eliot]]></category>
		<category><![CDATA[file aggregation]]></category>
		<category><![CDATA[http-request]]></category>
		<category><![CDATA[JSMin]]></category>
		<category><![CDATA[mozilla]]></category>
		<category><![CDATA[Nate Koechley]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[sliding doors]]></category>
		<category><![CDATA[techniques]]></category>
		<category><![CDATA[yahoo]]></category>
		<category><![CDATA[yui]]></category>

		<guid isPermaLink="false">http://learningtheworld.eu/2007/performance/</guid>
		<description><![CDATA[In the last six months I became more aware of techniques for optimizing website performance. I learned about memory leaks and JavaScript performance, but what impressed me most was Nate Koechleyâ€™s presentation about large scale website performance issues in â€œYahoo! <abbr title="versus">vs.</abbr> Yahoo!&#8221; at the @media conference 2006. In the meantime there have been more blog posts about particular aspects of performance optimization, so I wrote a summary.&#160;[&#8230;]]]></description>
				<content:encoded><![CDATA[<p>In the last six months I became more aware of techniques for <strong>optimizing website performance</strong>. I learned about <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/IETechCol/dnwebgen/ie_leak_patterns.asp" title="Microsoft Developer Network: Understanding and solving Internet Explorer leak patterns">memory</a> <a href="http://outofhanwell.com/ieleak/" title="Drip: A memory leak detector for Internet Explorer">leaks</a> and <a href="http://blogs.msdn.com/ie/archive/2006/08/28/728654.aspx" title="IE + JavaScript performance recommendations &ndash; part 1">JavaScript</a> <a href="http://blogs.msdn.com/ie/archive/2006/11/16/ie-javascript-performance-recommendations-part-2-javascript-code-inefficiencies.aspx" title="IE + JavaScript performance recommendations &ndash; part 2">performance</a>, but what impressed me most was <a href="http://nate.koechley.com/blog/2006/07/12/my_atmedia_2006_slides/" rel="met colleague">Nate Koechley&rsquo;s presentation</a> about large scale website performance issues in &ldquo;<a href="http://learningtheworld.eu/2006/atmedia-day-two/#koechley" title="See my notes about his talk">Yahoo! <abbr title="versus">vs.</abbr> Yahoo!</a>&rdquo; at the @media conference 2006. In the meantime there have been more blog posts about particular aspects of performance optimization, and I&rsquo;d like to sum them up:</p>

<p id="file-location"><strong>Parsing JavaScript</strong> freezes the browser. Therefore put <acronym title="Cascading Stylesheets">CSS</acronym> in the <code>head</code> and JavaScript near to the <code>&lt;/body&gt;</code> so that it is parsed when the page has been rendered.</p>

<p id="http-requests">The arch enemy of performance are <strong><a href="http://yuiblog.com/blog/2006/11/28/performance-research-part-1/" title="YUI Blog: Performance research &ndash; what the 80/20 rule tells us about reducing HTTP requests"><acronym title="Hypertext Transfer Protocol">HTTP</acronym> requests</a></strong>. Many browsers still can&rsquo;t handle more than two or four requests at a time. Keep the number of files down, your website will be faster.</p>

<p>There are several techniques with the aim to reduce the number of files:</p>

<ol><li id="inline-css"><p><strong>&ldquo;<q>A single large file is fastest.</q>&rdquo;</strong> (<cite>Nate Koechley</cite>) That&rsquo;s why Yahoo! <em>apparently</em> has such an amount of <a href="http://www.robertnyman.com/2007/01/24/with-these-web-sites-would-you-say-the-web-standards-war-is-won/">inline <acronym title="Cascading Stylesheets">CSS</acronym></a>. They found out <a href="http://yuiblog.com/blog/2007/01/04/performance-research-part-2/" title="YUI Blog: Performance research, part 2: browser cache usage &ndash; exposed!">browser caching</a> is not as effective as they thought, in particular not on a user&rsquo;s start page. So they deliver &ldquo;inline&rdquo; <acronym>CSS</acronym>. Actually writing inline <acronym>CSS</acronym> is a maintenance nightmare, but delivering <acronym>CSS</acronym> content inline doesn&rsquo;t mean the files can&rsquo;t have separate lives on the server: concatenate the files with a server side technique of your choice.</p>
<p><strong>Update:</strong> A couple of months later <a href="/2007/performance-2/#rule-8">Nate explained that further</a>: when your page is likely to be a user&rsquo;s start page, caching plays a minor role, thus &ldquo;inline&rdquo; <acronym>CSS</acronym> is faster. Otherwise use external files, aggregate them, and make sure they are cached (see below).</p></li>
<li id="enforce-caching"><p><strong>Enforce caching.</strong> Another <a href="http://www.bazon.net/mishoo/articles.epl?art_id=958"><acronym title="Internet Explorer">IE</acronym> bug</a> prevents image caching. Add the following to your <code>.htaccess</code>, <code>httpd.conf</code> or <code>vhost.conf</code> settings:</p>
<ol class="code">
<li><code>&lt;IfModule mod_expires.c&gt;</code></li>
<li class="indent"><code>ExpiresActive On</code></li>
<li class="indent"><code>ExpiresByType image/jpg &quot;access plus 1 day&quot;</code></li>
<li class="indent"><code>ExpiresByType image/jpeg &quot;access plus 1 day&quot;</code></li>
<li class="indent"><code>ExpiresByType image/gif &quot;access plus 1 day&quot;</code></li>
<li class="indent"><code>ExpiresByType image/png &quot;access plus 1 day&quot;</code></li>
<li><code>&lt;/IfModule&gt;</code></li></ol></li>
<li id="background-images"><p><strong>Reduce the number of background images</strong> with techniques like <a href="http://www.alistapart.com/articles/sprites/">CSS Sprites</a> or <a href="http://www.alistapart.com/articles/slidingdoors/">Sliding Doors</a>. Instead of four images of rounded corners you <a href="http://www.fiftyfoureleven.com/sandbox/sliding-doors-one-image/" title="Example">only need one</a> and get the mouseover state for free! The green download button on <a href="http://www.mozilla.com">mozilla.com</a> is based on that technique. And <a href="http://www.yahoo.com">Yahoo!</a> uses <acronym>CSS</acronym> Sprites to combine a huge number of icons.</p>

<p><img src="/wp-content/uploads/2007/01/mozilla-button.jpg" class="centered screenshot" width="300" height="149" alt="Download button on mozilla.com using the Sliding Doors technique" /></p>

<p>Please note this approach is only for <em>decorational background images</em> that degrade gracefully. <del>It&rsquo;s not for <code>img</code> elements.</del> <ins>Be careful when you use it for <a href="/2007/foreground-sprites/">foreground images</a>.</ins> And if text comes as a graphical representation, it can become inaccessible for screen reader users, zoom readers, or people with stylesheets switched off. Use real text instead.</p>

<p>Also note changing the <code>background-position</code> causes <acronym>IE6</acronym> to flicker, related to the caching bug above. To avoid it, simply add the following:</p>
<ol class="code">
<li><code>&lt;script type=&quot;text/javascript&quot;&gt;</code></li>
<li class="indent"><code>try { document.execCommand(<span class="codeSpace">&nbsp;</span>&quot;BackgroundImageCache&quot;, false, true); } catch(e) {};</code></li>
<li><code>&lt;/script&gt;</code></li></ol></li>
<li id="file-aggregation"><p><strong>Aggregate files.</strong> Ed Eliot wrote a nice <a href="http://www.ejeliot.com/blog/72" title="Automatic merging and versioning of CSS/JS files with PHP">script to merge JavaScript or <acronym>CSS</acronym> files</a>, bonus respect for the advanced versioning and caching features.</p>

<p>But remember the cases when it doesn&rsquo;t make sense to merge <acronym>CSS</acronym> files: your <acronym title="Internet Explorer">IE</acronym> bugfixes still belong in conditional comments. If you use the <code>@import</code> rule to filter antique browsers from getting advanced styles, you can&rsquo;t drop it. And if you want to merge stylesheets for different media (<abbr title="for example">e.g.</abbr> print), make sure the code is enclosed in something like</p>


<ol class="code">
<li><code>@media print {</code></li>
<li class="indent"><code>/* style sheet for print goes here */</code></li>
<li><code>}</code></li></ol>


<p>In an <a href="http://www.ejeliot.com/blog/73" title="Adding JSMin to the CSS/JS merging script">updated version</a> Ed added <a href="http://javascript.crockford.com/jsmin.html">JSMin</a> to strip comments and excess whitespace. JSMin works like a charm for JavaScript files. But it cuts a few space characters too much so that the syntax of <acronym>CSS</acronym> selectors changes <del>therefore for now I have abandoned the idea to compress them too</del>. <ins>See <a href="#comment-6045">Jens Meiert&rsquo;s comment</a> below for a recommendation to minimize <acronym>CSS</acronym>.</ins></p>

<p>His original code requires the C version of JSMin with PHP <code>safe_mode</code> turned off. If you prefer a pure PHP version, get the <a href="http://javascript.crockford.com/jsmin2.php.txt">PHP version of JSMin</a> and my <a href="/examples/combine-jsmin.phps" type="text/plain">adapted version of the script</a>.</p>
</li></ol>

<p>I&rsquo;m still in awe how fast one of my own websites became! Thanks to the guys at Yahoo! for the inspiration and for most of the research this article is based upon. Even JSMin was written by an employee of Yahoo! Speaking about Yahoo! employees: <a href="http://wait-till-i.com/" title="Christian Heilmann" rel="met colleague">Chris</a>, I hope there are still enough topics for your <a href="http://www.thinkvitamin.com/features/dev/enhance-your-page-performance" title="Chris Heilmann: Enhance your (page) performance!">Vitamin article</a>. I wanted to write about performance anyway, and to my surprise I <a href="http://www.robertnyman.com/2007/01/24/with-these-web-sites-would-you-say-the-web-standards-war-is-won/#comment-29959">read yesterday</a> that you have similar plans. See ya in <a href="/2007/brain-food/#e-accessibility" title="First European e-Accessibility Forum">Paris</a>. <img src="http://learningtheworld.eu/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /> </p>
]]></content:encoded>
			<wfw:commentRss>http://learningtheworld.eu/2007/performance/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
	</channel>
</rss>
