<?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>getiblog &#187; optimization</title>
	<atom:link href="http://blog.getify.com/tag/optimization/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.getify.com</link>
	<description>open-source, performance, javascript &#38; ui musings</description>
	<lastBuildDate>Mon, 23 Aug 2010 20:50:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A visual of page-load improvements (via LABjs)</title>
		<link>http://blog.getify.com/2009/12/a-visual-of-page-load-improvements-via-labjs/</link>
		<comments>http://blog.getify.com/2009/12/a-visual-of-page-load-improvements-via-labjs/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 07:21:23 +0000</pubDate>
		<dc:creator>getify</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[UI Architecture]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[labjs]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[page load]]></category>
		<category><![CDATA[ui]]></category>

		<guid isPermaLink="false">http://blog.getify.com/?p=156</guid>
		<description><![CDATA[If you run a website but you&#8217;re not aware of Google&#8217;s free Webmaster Tools, you need to get in the loop! These tools allow you to analyze a number of important aspects of how your site is viewed/analyzed by Google&#8217;s search engine index. 
Yet, with all the power and insight these tools give, it still [...]]]></description>
			<content:encoded><![CDATA[<p>If you run a website but you&#8217;re not aware of Google&#8217;s free <a href="https://www.google.com/webmasters/tools/">Webmaster Tools</a>, you need to get in the loop! These tools allow you to analyze a number of important aspects of how your site is viewed/analyzed by Google&#8217;s search engine index. </p>
<p>Yet, with all the power and insight these tools give, it still feels like it&#8217;s best-kept-secret kind of thing that such tools even exist. I never hear anyone talking or writing about them. But I fire them up probably at least once a month to keep an eye on my various sites.</p>
<p>But the hush-hush of Google&#8217;s toolset makes it more exciting to highlight a really cool addition announced today, the <a href="http://googlewebmastercentral.blogspot.com/2009/12/how-fast-is-your-site.html">new Site Performance tool</a>. True, it&#8217;s still in development and very early on, but it already is showing the promise to give great new insights into how your site is performing out in the wild.</p>
<p>We all got the hint a few weeks ago that <a href="http://searchengineland.com/site-speed-googles-next-ranking-factor-29793">Google is planning</a> to <a href="http://www.downloadsquad.com/2009/11/14/google-to-use-page-load-speed-as-a-search-result-ranking-factor/">start considering page-load speed in its indexing algorithm</a>. It would seem to be somewhat &#8220;evil&#8221; for the world&#8217;s largest search engine to start holding page-load speed against everyone&#8217;s sites without being part of the solution. So it shouldn&#8217;t be a surprise that the G would begin releasing various &#8220;tools&#8221; to help the rest of us actually make our sites load faster. </p>
<h2>Bye, bye, birdie!</h2>
<p>Yesterday, the Google Analytics team released a long-overdue update to their suggested snippet for including &#8220;ga.js&#8221; in pages. They wisely ditched the horrid &#8220;document.write()&#8221; approach that has been the standard for the longest time, in favor of this new <a href="http://googlecode.blogspot.com/2009/12/google-analytics-launches-asynchronous.html">asynchronous loading</a> technique. The reason? Quite obviously, this now will <strong>unblock</strong> the loading of GA from page loads, thus preventing Google from being at fault for slower load times!</p>
<p><strong>Side Note:</strong> the suggested code that Google has released has been shown not to be safe with all page structures in some browsers, including (ironically!) Chrome, and Opera. The problem is a faulty assumption that &#8220;document.documentElement.firstChild&#8221; will always return a reference to the HEAD element to append the &lt;script> to. As this <a href="http://yura.thinkweb2.com/jstests/document_head_test_by_Garrett.html">documentElement.childNodes test page</a> from <a href="http://twitter.com/kangax">@kangax</a> shows (if loading in Chrome or Opera, for instance), it&#8217;s (too) easy to accidentally create your page in such a way that this assumption will fail. So, be careful before you jump to switching to Google&#8217;s new snippet. (hint: use LABjs instead. Simpler, easier, and much more reliable!)</p>
<p>But, snarkiness aside, the new &#8220;Site Performance&#8221; tool proves its worth when it shows you a graph of your page&#8217;s estimated average load speeds over the last several months, along with a few basic statistics. It also incorporates a number of Google&#8217;s PageSpeed rules and suggestions for how to reduce factors that are slowing down your page loads.</p>
<p>This information is a really great place to start when trying to attack the performance issues your site may have. In fact, it may help you identify issues you didn&#8217;t even know existed!</p>
<h2>Where&#8217;s the visuals?</h2>
<p>Imagine my elation when I pulled up one of my larger, more traffic&#8217;d sites in the tool and saw this graph:</p>
<div id="attachment_157" class="wp-caption aligncenter" style="width: 557px"><img src="http://getiblog.2static.it/wp-content/uploads/2009/12/site-speed.png" alt="Site page-load performance improvements over last few months" title="site-speed" width="547" height="150" class="size-full wp-image-157" /><p class="wp-caption-text">Site page-load performance improvements over last few months</p></div>
<p>I went from an average of over 3.5 seconds per page load back in August down to a current average of less than 0.3 seconds, which the tool claims is better than 98% of sites! Oh, and btw, this site loads over 105k of JS, images, and CSS, so this isn&#8217;t some puny text-only site getting that kind of loading speed. It&#8217;s a testament to the results you can get if you start caring about page-load optimization on many fronts.</p>
<p>But you know the biggest and most obvious change I made back in July and August on the site in question? That&#8217;s right, you guessed it &#8212; that&#8217;s when I first installed early versions of <a href="http://labjs.com">LABjs</a> for all the site&#8217;s scripts. And over time, I&#8217;ve not only improved the efficiency and capabilities of LABjs, but I&#8217;ve also refined more and more how I work to address page load speeds. To be fair, optimizing script loading was only one of many strategies I used, including <a href="http://spriteme.com">CSS spriting</a> and combining/concat&#8217;ing of JS files to reduce the number of HTTP requests.</p>
<p><strong>But it&#8217;s plainly evident that LABjs was a critical part of this process!</strong></p>
<p>No matter what you feel about dynamic script loaders and if they are useful or not, it&#8217;s clear that all of us have to get more serious about improving our page-load performances if we don&#8217;t want to get left in the Google-index dust. I just believe that script loading is an easy and hugely impactful place to start that process. Remember: optimize, optimize, optimize.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.getify.com/2009/12/a-visual-of-page-load-improvements-via-labjs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LABjs: why not just concat?</title>
		<link>http://blog.getify.com/2009/11/labjs-why-not-just-concat/</link>
		<comments>http://blog.getify.com/2009/11/labjs-why-not-just-concat/#comments</comments>
		<pubDate>Sat, 28 Nov 2009 05:41:08 +0000</pubDate>
		<dc:creator>getify</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[UI Architecture]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[labjs]]></category>
		<category><![CDATA[loading]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[page]]></category>
		<category><![CDATA[ui]]></category>

		<guid isPermaLink="false">http://blog.getify.com/?p=97</guid>
		<description><![CDATA[Update
[8/12/2010: I've posted a performance benchmark test to try and gather some numbers from the crowd-at-large on how single large concat'd files perform compared to chunking that big file into a couple of smaller files to download in parallel. I encourage you to go right now and click each of the buttons a few times, [...]]]></description>
			<content:encoded><![CDATA[<h5>Update</h5>
<p>[<strong>8/12/2010:</strong> I've posted a performance benchmark test to try and gather some numbers from the crowd-at-large on how single large concat'd files perform compared to chunking that big file into a couple of smaller files to download in parallel. I encourage you to go right now and click each of the buttons a few times, and then spread the link on to others. <a href="http://test.getify.com/concat-benchmark/test-1.html" target="_blank">Concat Performance Benchmark Test #1</a>]</p>
<p>By far the most prevalent question circulating right now in the wake of <a<br />
href="http://labjs.com">LABjs</a>&#8216; <a href="http://blog.getify.com/2009/11/labjs-new-hotness-for-script-loading/">initial public launch</a> (IPL, I guess!?) is the understandable: &#8220;Why do I need a loader like LABjs for multiple files when I can just concat everything into one file?&#8221;</p>
<p>Fair enough, this is an important question to address. You shouldn&#8217;t just take my implied assumption at face value; we need to dig into this so you understand why I feel so strongly that LABjs offers something better than what you are probably currently doing on your sites.</p>
<p>The short answer is, <strong>BOTH</strong>! You should concat files together when possible, <em>and</em> you should load your file(s) with a loader like LABjs. If you only do one or the other, you have missed out on the bigger picture of page-load optimization.</p>
<h2>YSlow/PageSpeed only value reducing HTTP requests</h2>
<p>Before I get into specifics about why I think LABjs brings something new and beneficial to the table, let&#8217;s tackle what I consider to be an interesting but perhaps misleading &#8220;truth&#8221;. I am firmly in a minority camp in my skepticism that reduction of HTTP requests is <em>the only</em> answer to the question of how to load a site more efficiently &#8212; actually, to be more accurate, how to load a site&#8217;s <em>JavaScript</em> more efficiently.</p>
<p>I bet that you are recalling the YSlow rules and the tried-and-true practice that concat&#8217;ing all your JS files into one file for production is the surest way to speed up your page loads. And you&#8217;re probably doubting my credibility because I would question such a fundamental &#8220;truth&#8221; as HTTP request reduction.</p>
<p>It is true that, especially for the largest sites on the internet (millions of page-views per month and more), the sheer volume of HTTP requests from a typical page profile (dozens of images, multiple style sheets, half a dozen JS files, etc) quickly overloads internet connections, server load-balancers, the user&#8217;s device, and even the browser itself. And anything you can do to reduce that overload will go a long way toward helping the site load with acceptable performance.</p>
<p>Sites like Yahoo and Google have taught us the basic principles of HTTP request reduction as an effective way to cut down on the overall page loading delays. For instance, consider <a href="http://spriteme.com">Spriting to combine images</a>, CSS concatenation, and, yes, JavaScript concatenation. Some sites, like Digg, have even experimented with the extreme &#8212; inlining all page resources, even binary image data, into a single multi-part request! And just recently, we saw a <a href="http://limi.net/articles/resource-packages/">proposal for Resource Packaging</a> as <a href="http://blog.getify.com/2009/11/resource-packaging-silver-bullet/">another way</a> to combine multiple types of data into single responses for HTTP request reduction.</p>
<p>If you run a site that has well over 50 million page views per month (I sure don&#8217;t!), you probably would assert that this is the easiest and <em>most</em> effective page-load optimization. And I&#8217;d be hard-pressed to go up against the brightest and the best at the world&#8217;s largest web properties to suggest that it&#8217;s not true, at least at their page-view volume.</p>
<h2>What&#8217;s true is true. Period.</h2>
<p>Here&#8217;s what I will suggest: maybe, just maybe, what&#8217;s true for Google at a hundred-million page views <em>may not identically and exactly</em> be true for the vast majority of us running sites in the tens-of-thousands page view realm. The &#8220;big boys&#8221; are up in rarefied air, and from there they certainly have the request volume to test, re-test, and &#8220;prove&#8221; these various rules of optimization. But in the same way that water behaves in strange, almost contradictory ways at extremes of hot or cold temperature, maybe the <em>art</em> of optimizing page loads isn&#8217;t as simple as &#8220;1 http request is always better than 2.&#8221;</p>
<p>Even for small sites (like the one you&#8217;re currently reading!), it&#8217;s still vitally important to reduce page load time and optimize for faster page views. So, I&#8217;ll readily and eagerly admit that a <em>key strategy</em> in that effort is for all of us to work to reduce our HTTP request loads.</p>
<h2>OK, so you agree concat&#8217;ing is best?</h2>
<p>Not so fast. Like I said, this issue is more complex than I think most of us are ready to admit. Too easily, we run the YSlow plugin tests on our site, and when we reduce HTTP requests by concat&#8217;ing our JS files, because it tells us to, not only does our perceived page-load times decrease, but our YSlow grade goes up! Success! We&#8217;ve proved the hypothesis, there&#8217;s nothing more to say, right?</p>
<p><strong>I don&#8217;t think this in and of itself means you have achieved the pinnacle of page-load performance, you&#8217;ve simply taken the first of many steps toward nirvana.</strong></p>
<p>In my opinion, loading your JavaScript in an efficient and optimized way cannot be boiled down into a simple set of &#8220;rules&#8221; &#8212; you can take such &#8220;truths&#8221; as good places to start, but you still have to refine the strategies to fit your particular site and audience. Indeed, this will start to look more like an art than a science, if done correctly. </p>
<h2>I&#8217;m not so sure&#8230;</h2>
<p>Maybe by this point, you&#8217;re still not convinced there&#8217;s more to the story, and you&#8217;re probably starting to feel like LABjs doesn&#8217;t really have that much to offer you. </p>
<p>Before you go, let me just say this: even if you <strong>only</strong> ever have one JavaScript file on your site, because concat&#8217;ing is the way to go for you, and you think that by putting a single &lt;script> tag at the bottom of your page, you&#8217;ve achieved the ultimate JavaScript loading solution &#8212; <strong>there is still some benefit to using LABjs to load that one file.</strong></p>
<p>Why? A regular &lt;script> tag in the main HTML, even at the foot of your document, will always block the page&#8217;s loading completion, which means that users will still be &#8220;stuck&#8221; waiting for that file to complete before they can do anything with your page. Now, for some pages, you may really not want the users to do anything until the JavaScript fully processes everything, but most people agree that designing sites for progressive-enhancement is a positive thing.</p>
<p>So, if you can design your sites so that there&#8217;s something meaningful for the users to see or even <em>do</em> while they wait for the JS to kick in, they will probably be happier with your site than if you just make them wait. And that&#8217;s where LABjs comes in. Loading JavaScript dynamically <strong>unblocks</strong> the rest of the page&#8217;s resources (and <a href="http://blog.getify.com/2009/11/why-dom-ready-still-sucks/">DOM-ready</a>!), freeing the user from the iron grip of the hanging &#8220;almost loaded but not yet&#8221; feeling that most sites force upon their users.</p>
<p>Include the small 4k of LABjs (via an <strong>inline</strong> &lt;script> tag) into your page, and use it to load your single JavaScript file, and I believe your users will see an improved, even slightly, user-experience on page-load, as long <a href="http://blog.getify.com/2009/11/labjs-new-hotness-for-script-loading/#ux-labjs">as you&#8217;re careful</a> about it.</p>
<h2>OK, so maybe there is more to this loading thing</h2>
<p>Keep reading if you&#8217;re ready to take the <a href="http://en.wikipedia.org/wiki/Red_pill">Red Pill</a> and dive deeper down the rabbit hole.</p>
<p><strong>(&#8230; more &#8230;)</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.getify.com/2009/11/labjs-why-not-just-concat/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>LABjs: new hotness for script loading</title>
		<link>http://blog.getify.com/2009/11/labjs-new-hotness-for-script-loading/</link>
		<comments>http://blog.getify.com/2009/11/labjs-new-hotness-for-script-loading/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 08:21:06 +0000</pubDate>
		<dc:creator>getify</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[UI Architecture]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[labjs]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[page load]]></category>
		<category><![CDATA[ui]]></category>

		<guid isPermaLink="false">http://blog.getify.com/?p=69</guid>
		<description><![CDATA[What, you mean to tell me you&#8217;re not already loading your scripts with the new hot thing, LABjs?
Just kidding, you&#8217;re probably just now starting to hear about it. But let me tell you, it is the next big thing. I mean, when was the last time someone found a way to completely revamp the plain [...]]]></description>
			<content:encoded><![CDATA[<p>What, you mean to tell me you&#8217;re not already loading your scripts with the new hot thing, <a href="http://labjs.com/">LABjs</a>?</p>
<p>Just kidding, you&#8217;re probably just now starting to hear about it. But let me tell you, it is the <strong>next big thing</strong>. I mean, when was the last time someone found a way to completely revamp the plain ol&#8217; boring &lt;script&gt; tag and give it new life!?</p>
<p>All levity aside, LABjs stands for Loading And Blocking JavaScript. It&#8217;s a general purpose script loader that aims to be able to effectively load any script resource(s), from any location, into any page, at any time. It loads them all as parallel as the browser will allow, but maintains execution order when you express the need to do so in the usage of the API, for keeping dependencies safe.</p>
<p>LABjs&#8217; primary goal is to replace the &#8220;&lt;script&gt; tag soup&#8221; in your pages (you know, all that garbage that clutters up your &lt;head&gt; or the end of your &lt;body&gt;) with a simple and expressive API that gives you complete control over the loading and executing behavior of your scripts.</p>
<p><a href="http://labjs.com/releasenotes.php">LABjs 1.0</a>, just released yesterday, now sports the &#8220;preloading&#8221; feature, which is the culmination of several months of collaborative efforts with <a href="http://stevesouders.com">Steve Souders</a> to bring the best of his script loading work from his most recent book <a href="http://stevesouders.com/efws/links.php?ex#Chapter4">Even Faster Web Sites</a> (EFWS) together with the expressive power of LABjs. We hope the new release represents the best of both worlds, and a really strong, solid solution for loading JavaScript resources into your pages.</p>
<h2>What is &#8220;preloading&#8221; for?</h2>
<p>The primary idea behind the &#8220;preloading&#8221; feature is to &#8220;look ahead&#8221; in the chain of LABjs API calls and start loading all (or, strictly, as many as the browser will allow at a time) scripts at once, but doing so in a &#8220;preloading&#8221; way much like was common years back with preloading images into the cache via JavaScript techniques.</p>
<p>Since the scripts are only preloaded, and not actually executed, LABjs is free to control the execution order of the scripts, which allows it to preserve proper execution order if you use the API functions to express the need to &#8220;wait()&#8221; for dependencies.</p>
<h2>So, how does this improve loading of my page?</h2>
<p>In addition to making the scripts load in parallel with each other (as much as possible), the scripts also load in parallel with the rest of the page&#8217;s resources. This means that virtually all page resources will load at nearly the same time, rather than waiting for one to finish before the next starts, as is common in many current browsers&#8217; implementations of &lt;script&gt; tag behavior.</p>
<div id="attachment_74" class="wp-caption aligncenter" style="width: 660px"><img src="http://getiblog.2static.it/wp-content/uploads/2009/11/figure11.png" alt="FF3, loading scripts serially with each other and page resources. 16.84s" title="FF3 loading resources. 16.84s" width="650" height="96" class="size-full wp-image-74" /><p class="wp-caption-text">FF3, loading scripts serially with each other and page resources. 16.84s</p></div>
<p>Notice how the 3 script files load in succession, and only after they complete do the images start to download (at least <em>those</em> download in parallel!). 16.84 seconds to download serially.</p>
<div id="attachment_84" class="wp-caption aligncenter" style="width: 660px"><img src="http://getiblog.2static.it/wp-content/uploads/2009/11/figure21.png" alt="FF3.5, loading scripts in parallel with each other, but still blocking page resources. 10.69s" title="FF3.5 loading resources. 10.69s" width="650" height="96" class="size-full wp-image-84" /><p class="wp-caption-text">FF3.5, loading scripts in parallel with each other, but still blocking page resources. 10.69s</p></div>
<p>FF3.5 introduced a nice new behavior in that they will download scripts in parallel, but still maintain execution order. So, in this diagram, we see that the scripts are parallel to each other, but still they block other page resources. Down to 10.69 seconds loading all resources.</p>
<div id="attachment_86" class="wp-caption aligncenter" style="width: 660px"><img src="http://getiblog.2static.it/wp-content/uploads/2009/11/figure31.png" alt="LABjs, loading scripts in parallel with each other and other page resources. 6.24s" title="LABjs loading resources (in virtually all browsers)" width="650" height="96" class="size-full wp-image-86" /><p class="wp-caption-text">LABjs, loading scripts in parallel with each other and other page resources. 6.24s</p></div>
<p>This diagram shows the loading behavior of LABjs in <strong>virtually all browsers</strong>, modern and not-so-modern. Notice that not only are scripts loaded in parallel to each other (while still maintaining execution order when necessary), but in parallel with other page resources as well. This means that you can use a much larger slice of the browser&#8217;s bandwidth to grab page resources as quickly as possible, speeding up the loading of the page by significant amounts (generally 2x to 3x speed increase). </p>
<p><strong>In this example, we went from 16.84s down to 6.24s. That&#8217;s a 2.7x speed increase. Now that&#8217;s something to get excited about!</strong><br />
<a name="ux-labjs"></a></p>
<h2>Are there any negative side effects?</h2>
<p>LABjs (and other dynamic script loaders like it) are so good at getting page resources and scripts to load more quickly, it unintentionally creates a lesser seen phenomenon in web user-experience that I am calling &#8220;FUBC&#8221; (flash of un-behaviored content) &#8212; pronounce it &#8220;fubik&#8221; &#8212; which is a takeoff of the more commonly known FOUC (flash of un-styled content).</p>
<p>FUBC means that it is possible that your raw (but still CSS styled) content may arrive to a page and even be displayed momentarily before your JavaScript has had a chance to kick in and attach behaviors or modify it. For some sites, the changes made by JavaScript behaviors are subtle and most users won&#8217;t notice. But for other sites, the &#8220;flash&#8221; between the two views of the content is much more drastic and jarring.</p>
<p>Because this can be a potentially disruptive user-experience, I suggest the following simple steps to address the FUBC phenomenon:</p>
<ol>
<li>
	In your main CSS of your page, hide (display:none or visibility:hidden) all content which will have drastic re-rendering by your JavaScript.
	</li>
<li>
	In your JavaScript, make sure to re-display/unhide the content once it has been styled by your code.
	</li>
<li>
	To take care of users who do not have JavaScript enabled, put a &lt;noscript> block in the &lt;head> of your page that unhides any<br />
	content hidden by your main CSS &#8212; essentially, undo the CSS hiding of content, since there won&#8217;t otherwise be any JavaScript to do so.
	</li>
</ol>
<p>By taking these 3 simple steps, you will effectively address the disruptive FUBC user-experience for JavaScript-enabled users, while still preserving proper display for the non-JavaScript crowd.</p>
<h2>Anything else?</h2>
<p>There are a couple of <a href="http://labjs.com/description.php#whennottouse">minor caveats</a> where LABjs may not be appropriate for your site or scripts. One specifically you should be aware of is the implications of <a href="http://blog.getify.com/2009/11/why-dom-ready-still-sucks/">LABjs with DOM-ready and frameworks like jQuery</a>.</p>
<p>But overall, there are just <a href="http://labjs.com/description.php#whentouse">so many reasons <strong>to</strong> use LABjs</a>. Why not give it a shot, see if helps your page load speed?</p>
<h2>I&#8217;m ready! So how do I use LABjs?</h2>
<p>To start, simply find your nearest &#8220;&lt;script> tag soup&#8221; in a page, and replace it with $LAB API calls, like this:</p>
<p>Old and busted:</p>
<pre style="background-color:#ddd;">
&lt;script src="framework.js">&lt;/script>
&lt;script src="plugin.framework.js">&lt;/script>
&lt;script src="myplugin.framework.js">&lt;/script>
&lt;script src="init.js">&lt;/script>
</pre>
<p>New hotness:</p>
<pre style="background-color:#ddd;">
$LAB
.script("framework.js")<b>.wait()</b>
.script("plugin.framework.js")
.script("myplugin.framework.js")<b>.wait()</b>
.script("init.js");
</pre>
<p>In the above example, all scripts <b>load</b> in parallel (by default). &#8220;framework.js&#8221; needs to execute first, before the others. But &#8220;plugin.framework.js&#8221; and &#8220;myplugin.framework.js&#8221; have no dependencies between them, so their execution order is not important (first-come, first-served). &#8220;init.js&#8221; needs to wait for all 3 scripts to execute before it runs.</p>
<p>The <a href="http://labjs.com/documentation.php#api">LABjs API</a> has a number of other options and alternate usage patterns, so check out the <a href="http://labjs.com/documentation.php">Documentation</a> and the <a href="http://labjs.com/test_suite">Test Suite</a> for more information.</p>
<h2>Responsibility</h2>
<p>I firmly believe it is all our responsibility to do what we can to make the web a better place to live. One of the best ways we can do that is to reduce the amount of time it takes to load friggin&#8217; web pages! So get to it, go <a href="http://labjs.com/download.php">download LABjs</a> right away and give your site a makeover in the &lt;script> tag department!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.getify.com/2009/11/labjs-new-hotness-for-script-loading/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Resource Packaging? Silver Bullet?</title>
		<link>http://blog.getify.com/2009/11/resource-packaging-silver-bullet/</link>
		<comments>http://blog.getify.com/2009/11/resource-packaging-silver-bullet/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 18:03:43 +0000</pubDate>
		<dc:creator>getify</dc:creator>
				<category><![CDATA[UI Architecture]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[delivery]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[packaging]]></category>
		<category><![CDATA[resources]]></category>
		<category><![CDATA[ui]]></category>

		<guid isPermaLink="false">http://blog.getify.com/?p=23</guid>
		<description><![CDATA[There&#8217;s been some buzz lately about a proposal for a technique of UI delivery optimization called Resource Packaging. Steve Souders weighed in on the proposal with resounding support.
Essentially, the idea is that web developers could proactively create .ZIP files of various page resources (images, CSS, JS, etc), and include in their page a special &#60;link> [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s been <a href="http://ajaxian.com/archives/resource-packages-making-a-faster-web-via-packaging">some buzz</a> lately about a proposal for a technique of UI delivery optimization called <a href="http://limi.net/articles/resource-packages/">Resource Packaging</a>. Steve Souders <a href="http://www.stevesouders.com/blog/2009/11/18/fewer-requests-through-resource-packages/">weighed in on the proposal</a> with resounding support.</p>
<p>Essentially, the idea is that web developers could proactively create .ZIP files of various page resources (images, CSS, JS, etc), and include in their page a special &lt;link> tag pointing to that &#8220;package&#8221;. Smart, elite browsers (like FF 3.7!?) would grab this resource package, unzip and cache the resources, and ostensibly then know how to skip trying to download them from their normal references in the rest of the HTML page. The idea is of course the all-important, oft-mentioned &#8220;reduce HTTP requests down to the most absolute minimum possible&#8221; rule that we all have blazened into our psyche.</p>
<h2>Wait, you mean you don&#8217;t agree with HTTP request reduction?</h2>
<p>On it&#8217;s surface, I don&#8217;t disagree with &#8220;minimize HTTP requests&#8221;. Certainly that&#8217;s a good and very important goal. If you needlessly create additional requests because you are ignorant or lazy and fail to employ even simple strategies (like image spriting, for instance), you are asking to crash your server(s) when your traffic increases.</p>
<p>But I believe there&#8217;s a paranoia spreading in the UI development and production community that the reduction of HTTP requests is penultimate and more important than any other strategy, to the exclusion of alternative perfectly reasonable practices for UI delivery optimization. </p>
<p>For instance, you hear people all the time say, &#8220;concat all your JavaScript into one file&#8221; for production. But is this really the right approach? I won&#8217;t go into the details here of why I disagree with this as a blanket approach, as I cover that <a href="http://blog.getify.com/2009/11/labjs-why-not-just-concat/">fully in this post</a>, but suffice it to say, I think we must balance HTTP request reduction paranoia against some other sanity checks.</p>
<h2>So what&#8217;s wrong with resource packaging?</h2>
<p>I have a number of issues with this idea. Let me lay them out for you:</p>
<p>In reality, what I&#8217;m <em>most</em> worried about is that this&#8217;ll be seen as the silver bullet and just deployed in widespread and often under-optimized ways, and will propogate what I think is a dangerous anti-pattern: People are so paranoid about HTTP request overhead (because let&#8217;s face it, we all think our site will get slashdot&#8217;d or hit digg.com homepage so we better be ultra-micro-optimized for millions of hits per minute!) that they&#8217;ll just default to putting everything in one resource package.</p>
<p>When that seems to work well in their dev environment, they&#8217;ll just roll that out and blindly think it&#8217;s ok. When you give people a dangerous amount of rope, it&#8217;s hard to not expect at least a good number of people will hang themselves with it.</p>
<p>Remember the good ol&#8217; days, when people created full-page flash sites, and when you visited the site, you sat and mindlessly watched a preloader animation while megabytes of content were all loaded at once? Oh, that was fun. I miss those days.</p>
<p>No, wait! I don&#8217;t miss that at all. Actually, I love that now we as a collective community realize that a critical part of user-experience is <strong>initial page loading</strong> behavior. I love that <a href="http://www.directtrafficmedia.co.uk/News/SEO_Must_Consider_Page_Speed_for_Google_Rankings_in_2010_51117540380.html">Google is going to start ranking pages based on how well they load</a>. This is a healthy, even if slightly uncomfortable, nudging in the right direction.</p>
<p>But worse yet, if abused (either intentionally or not), I think this pattern will have worse overall performance than if people had just left their sites as they currently are.</p>
<p>Compare this type of approach to say someone taking more targetted/focused approaches to UI optimization. For instance, you could use <a href="http://labjs.com">LABjs</a> for loading scripts in parallel with each other and the rest of the page resources&#8230; or use <a href="http://spriteme.com">spriting</a>&#8230; or how about css concatenation? </p>
<p>Each of those techniques is more narrow in focus and has much less potential for going wrong when employed, in terms of both pattern <strong>and</strong> practice. But one big single &#8220;solution to rule them all&#8221; has both enough upside <strong>and</strong> downside that I fear it could go seriously off track if used wrongly.</p>
<h2>Aren&#8217;t YOU just being paranoid or pessimistic about web developer ignorance?</h2>
<p>In addition to the potential improper usage patterns, I also think there are tangible issues that the proposal and Souders&#8217; post don&#8217;t address, at least not completely:</p>
<ol>
<li>Relying on a technique which only works (in any forseeable future) in one (or a couple at best) browser(s) will promote yet another anti-pattern&#8230; optimizing for a subset of browsers and ignoring performance in other browsers.
<p>I know there&#8217;s lots of people out there who find it vogue to discard performance in IE and say &#8220;well, the deserve what they get for using a crappy browser.&#8221; But I don&#8217;t think that&#8217;s productive or realistic. Wouldn&#8217;t our time be better spent finding (and educating about!) new ways (like LABjs, spriting, css concatenation) to optimize the UI performance that <strong>will</strong> improve things in practically <strong>all</strong> browsers? </p>
<p>Doesn&#8217;t that serve the web community better than just myopically focusing on one (admittedly growing) segment that uses a bleeding-edge browser version and implements a new feature idea before it&#8217;s even really a standard?</li>
<li>What about resources that are CDN&#8217;d? Sure, you host some of your resources locally, but hopefully you are moving toward putting more and more of your stuff remotely, out on the edge, via CDN&#8217;s. There&#8217;s no doubt this is a powerful technique, and is only going to increase in importance.
<p>And forget CDN&#8217;s (at least technically) for the moment. I&#8217;ve never once rolled out a site where I didn&#8217;t link to at least one or a couple of remote resources. For instance, I use Google Analytics on all my pages, I often use an AddThis social badge script (and images), Google Groups forms and images, etc, etc, etc. What should I do with all these non-local page resources?</p>
<p>So do you really even have <em>that many</em> resources locally that it makes sense to package? And what if people employ another anti-pattern and start hosting and packaging locally what could have otherwise been better hosted remotely (CDN or not) and shared globally? Are we going to keep relying on browsers to get smarter and smarter, enough that now they can resolve all these local vs. remote/CDN versions of files in the Package Manifest for us and choose the correct ones?</p>
<p>I get scared when I start thinking about the browser trying to be smarter than I am about how it optimizes UI delivery performance.</li>
<li>What about parallel downloading? If you load a single file and it&#8217;s 1 MB in size, the browser will likely download that thing byte-by-byte, serially. At least until we get to using BitTorrent for our page resources!
<p>But wait, what if you downloaded 3 files instead? It&#8217;d download in roughly 1/3 the time, right? That&#8217;s cool. Now, that math doesn&#8217;t stretch on forever&#8230; obviously there&#8217;s a point where the overhead of HTTP Requests starts to degrade the power of parallel downloading. But there&#8217;s got to be some balance, some sweet spot between 1 file and 100 files? </p>
<p>And I bet that number varies from site to site. For some, maybe it&#8217;s 2. For others, maybe it&#8217;s 4. So this is one more variable that web deployment engineers have to experiment with and figure out the black magic of what&#8217;s best for their site. Again, I bet most will end up punting on multiple resource packages and will just use one file. I doubt this will be a good thing for most sites.</p>
<p>Remember this (pessimism or realism): if figuring out what&#8217;s best is not intuitive, <em>most</em> won&#8217;t do it.</li>
</ol>
<p>Here&#8217;s the bottom line: Resource Packaging sounds good in theory. But I suspect the practice of it will be quite flawed, and we&#8217;ll have yet another dimension of suckiness out in the UI delivery world that we&#8217;ll all have to wade through and educate on how to get it right.</p>
<h2>Ding!</h2>
<p>Wait, I just thought of something! While we&#8217;re at the business of packaging things up to reduce requests&#8230; how about we <strong>JUST</strong> deliver a zip file to the browser, which includes everything, even the HTML for the page? </p>
<p>In fact, does it even need to be a ZIP file? What about if we could figure out a special file format (which I&#8217;m sure wouldn&#8217;t ever get bogged down in proprietary rights/trademarks or disagreements over specification), and in that way we can make that single file really optimized (&#8220;compiled&#8221;), and the browser could just get really smart about &#8220;executing&#8221; our page for us? We&#8217;d achieve the all-imporant single-page, single HTTP-request &#8220;golden ratio&#8221;.</p>
<p>And for all those old, busted, non-conforming (non-bleeding-edge) browsers, we&#8217;ll just ask users to install a plugin to assist the browser in processing the page. People like plugins, right?</p>
<p>Oh, wait. Nope. We&#8217;ve tried that before. Many times. It was called Java. Then it was called Flash. Now it&#8217;s called Silverlight or JavaFX. And thankfully we&#8217;ve evolved to a higher level of consciousness. Or so I hope.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.getify.com/2009/11/resource-packaging-silver-bullet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Loading JavaScript: Even a caveman can do it</title>
		<link>http://blog.getify.com/2009/11/loading-javascript-even-a-caveman-can-do-it/</link>
		<comments>http://blog.getify.com/2009/11/loading-javascript-even-a-caveman-can-do-it/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 06:46:44 +0000</pubDate>
		<dc:creator>getify</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[UI Architecture]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[compression]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[loading]]></category>
		<category><![CDATA[minification]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[ui]]></category>

		<guid isPermaLink="false">http://blog.getify.com/?p=8</guid>
		<description><![CDATA[I recently gave a talk about JavaScript Loading at JSConf.EU in Berlin. Video/audio of the talk will be made available online eventually, and I will link to it here once that happens. But, in fact, I will be re-presenting this same talk at the November meeting of Austin.Javascript (@AustinJS), on Tues Nov 17th, at 7:30pm. [...]]]></description>
			<content:encoded><![CDATA[<p>I recently gave a <a href="http://www.slideshare.net/shadedecho/loading-javascript-even-a-caveman-can-do-it">talk about JavaScript Loading</a> at <a href="http://jsconf.eu">JSConf.EU</a> in Berlin. Video/audio of the talk will be made available online eventually, and I will link to it here once that happens. But, in fact, I will be re-presenting this same talk at the November meeting of Austin.Javascript (<a href="http://twitter.com/austinjs">@AustinJS</a>), on <a href="http://www.linkedin.com/groupAnswers?viewQuestionAndAnswers=&#038;gid=1913658&#038;discussionID=9818762">Tues Nov 17th, at 7:30pm</a>. Come join us if you can! My hope is to push the envelope of how we all approach loading JavaScript resources into our pages.</p>
<p>The talk covers a number of different strategies, each of which I will be covering in subsequent posts here. But I wanted to give a quick overview of what you can expect:</p>
<ol>
<li><strong>Build-time optimization:</strong> it&#8217;s important to utilize build-process optimizations to manage local scripts and dependency chains. Depending on your server architecture and frameworks, there are lots of different choices that you have here, but the key is have a system that can manage this intelligence for you, freeing you and the other developers on your team from having to maintain the techniques yourselves.</li>
<li><strong>Load/run-time profiling:</strong> We&#8217;ve all heard the advice that the best way to get JavaScript resources onto the page is to only have one JavaScript file, meaning we should always concat all our individual files into one massive output file as it goes to the browser in production. But does this always make sense? I believe it only rarely does.
<p>There are a number of tools for profiling your site/application at load-time and at run-time, to decide what parts of your JavaScript are critical to load at the beginning, and what parts can be safely deferred until later and be lazy-loaded. Doing so not only speeds up the load time user-experience of your site/application, but it also often helps create better long(er)-term user-experience by more effectively utilizing the user&#8217;s browser cache. You can profile manually, or automatically, but you shouldn&#8217;t ever put a site or application into production without at least examining these strategies and trying a few different options.</li>
<li><strong>Post-optimize your minified JavaScript:</strong> For a long time, it felt like the book was closed on minification/obfuscation. There&#8217;s only so much white-space you can remove from a JavaScript file, and only so many variable names you can shorten, before a script seems as small as it&#8217;s going to get. But, it would seem there are more chapters to be written, yet.
<p>Recent releases of projects like Google Closure prove that there&#8217;s a lot more ground to cover on what we can do to optimize and shorten our scripts. I also have a project called <a href="http://mincir.it">Mincir</a> which is aimed at specifically running post-minification optimization steps on files to squeeze out more bytes. Smaller files means quicker loading and better user-experience. And that means happier users and happier developers.</li>
<li><strong>Dynamic, on-demand, parallel loading of JavaScript:</strong> While the landscape of how the browsers handle the &lt;script> tag is quite diverse and often ugly, there are ways to normalize this behavior cross-browser, and in the process allow all your JavaScript resources to load at the same time, in parallel with each other and the rest of the page assets. This is actually not that hard. But ensuring proper execution order, not only of loaded scripts, but also of coupled inline script executions, is where the magic happens.
<p>Luckily, a project of mine, called <a href="http://labjs.com">LABjs</a>, does just such a thing. It&#8217;s a general purpose, flexible, and capable JavaScript loader, that allows you to load just about any script or group of scripts onto any page, at any time.</li>
<li><strong>Load and cache &#8220;not-code&#8221;, execute &#8220;code&#8221; later:</strong> Sometimes, the best way to get JavaScript onto the page is not to load JavaScript at all. This may seem like a crazy statement, but you actually have some options as to how your &#8220;code&#8221; gets delivered to the page. For instance, you can transfer the code inside a multi-line comment block, or even as an escaped string literal assigned to a JavaScript variable. You may ask, why would I do such a crazy thing? Well, it turns out that there&#8217;s a significant amount of time spent processing JavaScript once it&#8217;s loaded onto a page.
<p>So, if on one page you want to &#8220;preload&#8221; a script into the cache for use on a subsequent page, like you have done with images for years, you pay a penalty for that script simply being added to your page. Unless of course it&#8217;s not really a script at that point. If it&#8217;s a comment or a string literal, then it is loaded and saved into the browser cache, but there&#8217;s almost no processing time on the page at that point. Later, on another page, you can recall this &#8220;not-code&#8221; from cache, and transform it into executable code. </p>
<p>This type of technique is quite valid for desktop browsers, but is particularly helpful for mobile browsers where the biggest bottleneck is not actually usually the  connection speed but the processing power of the mobile device in handling large amounts of not-used-yet code while rendering a page.</li>
</ol>
<p>None of these techniques are in and of themselves a complete solution to this issue, nor are these ideas the final word on the topic. But it&#8217;s time we evolve how we load our JavaScript onto pages and move beyond the 1990&#8217;s version of the plain ol&#8217; &lt;script> tag. I hope this talk and these posts will get that ball rolling.</p>
</p>
<div style="width:425px;text-align:left" id="__ss_2452641">
<div><a href="http://www.slideshare.net/shadedecho/loading-javascript-even-a-caveman-can-do-it" title="Loading JavaScript: Even a caveman can do it">Loading JavaScript: Even a caveman can do it</a></div>
</p>
<p><object style="margin:0px" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=caveman-091108165033-phpapp02&#038;stripped_title=loading-javascript-even-a-caveman-can-do-it" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><param name="wmode" value="opaque"/><embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=caveman-091108165033-phpapp02&#038;stripped_title=loading-javascript-even-a-caveman-can-do-it" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355" wmode="opaque"></embed></object>
<div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;">View more <a style="text-decoration:underline;" href="http://www.slideshare.net/">presentations</a> from <a style="text-decoration:underline;" href="http://www.slideshare.net/shadedecho">Kyle Simpson</a>.</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.getify.com/2009/11/loading-javascript-even-a-caveman-can-do-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Content Delivery Network via getiblog.2static.it

Served from: blog.getify.com @ 2010-09-07 21:00:06 -->