<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: LABjs: how to deal with inline code</title>
	<atom:link href="http://blog.getify.com/2009/11/labjs-how-to-deal-with-inline-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.getify.com/2009/11/labjs-how-to-deal-with-inline-code/</link>
	<description>open-source, performance, javascript &#38; ui musings</description>
	<lastBuildDate>Tue, 07 Sep 2010 17:21:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Kevin Hakanson</title>
		<link>http://blog.getify.com/2009/11/labjs-how-to-deal-with-inline-code/comment-page-1/#comment-535</link>
		<dc:creator>Kevin Hakanson</dc:creator>
		<pubDate>Wed, 18 Aug 2010 19:36:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.getify.com/?p=122#comment-535</guid>
		<description>I had a similar problem with multiple inline script blocks, but I was unable to combine them into one because they came from different components.  After I realized the chain was instance based, I &quot;continued&quot; the chain by keeping the reference in a global variable, and using it in my future inline script block.

Here&#039;s this posts sample code, rewritten with my technique:

&lt;pre style=&quot;background-color:#ddd;&quot;&gt;
  var instance = $LAB
  .script(&quot;framework.js&quot;)
  .script(&quot;myscript.js&quot;)
  .wait(function(){ myscript.init(); });


  instance.wait(function(){ 
    framework.init();
    framework.doSomething();
  });
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I had a similar problem with multiple inline script blocks, but I was unable to combine them into one because they came from different components.  After I realized the chain was instance based, I &#8220;continued&#8221; the chain by keeping the reference in a global variable, and using it in my future inline script block.</p>
<p>Here&#8217;s this posts sample code, rewritten with my technique:</p>
<pre style="background-color:#ddd;">
  var instance = $LAB
  .script("framework.js")
  .script("myscript.js")
  .wait(function(){ myscript.init(); });

  instance.wait(function(){
    framework.init();
    framework.doSomething();
  });
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arun Basnet</title>
		<link>http://blog.getify.com/2009/11/labjs-how-to-deal-with-inline-code/comment-page-1/#comment-520</link>
		<dc:creator>Arun Basnet</dc:creator>
		<pubDate>Fri, 06 Aug 2010 23:15:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.getify.com/?p=122#comment-520</guid>
		<description>Great! 
Thank you so much! I guess I referred to quite old posts to have used .block. :D
The one I&#039;d referred to here :
http://ajaxian.com/archives/labjs-simple-abstraction-for-loading-dependencies-correctly
-- 
said quite clearly in the example:
old=&gt;





new=&gt;
&lt;pre style=&quot;background-color:#ddd&quot;&gt;
$LAB
.script(&quot;jquery.js&quot;)
.block(function(){
      $LAB
      .script(&quot;jquery.ui.js&quot;)
      .script(&quot;myplugin.jquery.js&quot;)
      .block(function(){
            $LAB.script(&quot;initpage.js&quot;);
      });
});
&lt;/pre&gt;

I know its wrong now.
Thank you again

I think I&#039;m clear about it now. 

Thanks a lot again!</description>
		<content:encoded><![CDATA[<p>Great!<br />
Thank you so much! I guess I referred to quite old posts to have used .block. <img src='http://getiblog.2static.it/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
The one I&#8217;d referred to here :<br />
<a href="http://ajaxian.com/archives/labjs-simple-abstraction-for-loading-dependencies-correctly" rel="nofollow">http://ajaxian.com/archives/labjs-simple-abstraction-for-loading-dependencies-correctly</a><br />
&#8211;<br />
said quite clearly in the example:<br />
old=&gt;</p>
<p>new=&gt;</p>
<pre style="background-color:#ddd">
$LAB
.script("jquery.js")
.block(function(){
      $LAB
      .script("jquery.ui.js")
      .script("myplugin.jquery.js")
      .block(function(){
            $LAB.script("initpage.js");
      });
});
</pre>
<p>I know its wrong now.<br />
Thank you again</p>
<p>I think I&#8217;m clear about it now. </p>
<p>Thanks a lot again!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: getify</title>
		<link>http://blog.getify.com/2009/11/labjs-how-to-deal-with-inline-code/comment-page-1/#comment-519</link>
		<dc:creator>getify</dc:creator>
		<pubDate>Fri, 06 Aug 2010 22:17:07 +0000</pubDate>
		<guid isPermaLink="false">http://blog.getify.com/?p=122#comment-519</guid>
		<description>@Arun- unfortunately, I don&#039;t know of any great examples out there other than this blog post and perhaps a few articles strewn about. I&#039;m still the main person promoting how LABjs actually works. Hope eventually more others will pick up the mantle.

To try and clarify for you: A single $LAB chain consists of a starting $LAB followed by a chain of one or more .script() calls and .wait() calls, interspersed as you need them to be. You should always try to avoid *multiple* $LAB calls, as they operate completely independently. Also, by nesting a $LAB inside a .wait(), you prevent that chain from even *loading* until the .wait() has executed. By doing a single chain with all your scripts, LABjs can load them *all* in parallel, but control their execution order based on where you have .wait() calls. That&#039;s what .wait() is for, to ensure *execution* order.

As for your $document.ready()... the use of $document.ready() is entirely separate from and orthagonal to the order of your scripts loading. It is only for making sure some logic doesn&#039;t run until the dom is ready. LAB script loads *do not* affect dom readiness at all (they don&#039;t hold it up) so there&#039;s no connection that you should make between sequencing $LAB with document.ready.

Instead, you should load all your scripts with LABjs and use .wait() where it&#039;s most appropriate to run code. If that code happens to be dependent on the dom-readiness, wrap the code (inside your .wait()) with a document.ready. In some cases, your scripts may load and execute before dom-ready, and thus your logic will protected to run later when the dom is ready. In other cases, dom-ready will pass before your scripts load and execute, and using document.ready() will essentially pass through and execute immediately.

If the code you need to wrap in $(document).ready() only cares about jquery, and not about the plugins, then do this:

&lt;pre style=&quot;background-color:#ddd;&quot;&gt;
$LAB
.script(&quot;jquery.js&quot;)
.wait(function(){
   $(document).ready(function() {  /* do something */ });
})
.script(&quot;plugin1.js&quot;)
.....
&lt;/pre&gt;

If the code you have to run needs the plugin to be there, then do it this way:
&lt;pre style=&quot;background-color:#ddd;&quot;&gt;
$LAB
.script(&quot;jquery.js&quot;)
.wait()
.script(&quot;plugin1.js&quot;)
.wait(function(){
   $(document).ready(function() {  /* do something */ });
});
&lt;/pre&gt;

Does that make sense more now?</description>
		<content:encoded><![CDATA[<p>@Arun- unfortunately, I don&#8217;t know of any great examples out there other than this blog post and perhaps a few articles strewn about. I&#8217;m still the main person promoting how LABjs actually works. Hope eventually more others will pick up the mantle.</p>
<p>To try and clarify for you: A single $LAB chain consists of a starting $LAB followed by a chain of one or more .script() calls and .wait() calls, interspersed as you need them to be. You should always try to avoid *multiple* $LAB calls, as they operate completely independently. Also, by nesting a $LAB inside a .wait(), you prevent that chain from even *loading* until the .wait() has executed. By doing a single chain with all your scripts, LABjs can load them *all* in parallel, but control their execution order based on where you have .wait() calls. That&#8217;s what .wait() is for, to ensure *execution* order.</p>
<p>As for your $document.ready()&#8230; the use of $document.ready() is entirely separate from and orthagonal to the order of your scripts loading. It is only for making sure some logic doesn&#8217;t run until the dom is ready. LAB script loads *do not* affect dom readiness at all (they don&#8217;t hold it up) so there&#8217;s no connection that you should make between sequencing $LAB with document.ready.</p>
<p>Instead, you should load all your scripts with LABjs and use .wait() where it&#8217;s most appropriate to run code. If that code happens to be dependent on the dom-readiness, wrap the code (inside your .wait()) with a document.ready. In some cases, your scripts may load and execute before dom-ready, and thus your logic will protected to run later when the dom is ready. In other cases, dom-ready will pass before your scripts load and execute, and using document.ready() will essentially pass through and execute immediately.</p>
<p>If the code you need to wrap in $(document).ready() only cares about jquery, and not about the plugins, then do this:</p>
<pre style="background-color:#ddd;">
$LAB
.script("jquery.js")
.wait(function(){
   $(document).ready(function() {  /* do something */ });
})
.script("plugin1.js")
.....
</pre>
<p>If the code you have to run needs the plugin to be there, then do it this way:</p>
<pre style="background-color:#ddd;">
$LAB
.script("jquery.js")
.wait()
.script("plugin1.js")
.wait(function(){
   $(document).ready(function() {  /* do something */ });
});
</pre>
<p>Does that make sense more now?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arun Basnet</title>
		<link>http://blog.getify.com/2009/11/labjs-how-to-deal-with-inline-code/comment-page-1/#comment-517</link>
		<dc:creator>Arun Basnet</dc:creator>
		<pubDate>Fri, 06 Aug 2010 18:43:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.getify.com/?p=122#comment-517</guid>
		<description>Hi, 

Many thanks for the brief insight! I will keep it in mind. 

Also, I really think that there are a lot of novice labjs users who are confused like I&#039;ve been. Could you please post some links to examples of LABjs used with various javascript libraries like jquery , yui etc. ?

I had a very hard time coming across examples of labjs on the internet. :(
Also, I thought I was doing the right thing loading dependent group of scripts (e.g., jquery.validate, jquery.form, etc.) into a single .block (I&#039;ll use .wait now on though) that would load after the jquery library is loaded.

Looking at your example above, I think I still am not 100% sure.

Due to the dependency of validate and jquery form upon jquery, I assume the following would be efficient - I am assuming that validate and form will both loading in parallel after jquery.js finishes loading :
--
$LAB
.script(&#039;jquery.js&#039;).wait(function(){$LAB.script(&#039;jquery.validate.js&#039;).wait().script(&#039;jquery.form.js&#039;)})

But you stated above:
--
$LAB
.script(&#039;jquery.js&#039;).wait().script(&#039;jquery.validate.js&#039;).script(&#039;jquery.form.js&#039;).wait();

which looks much simpler than expected! So if I am assuming it wrong and the example you&#039;ve given is how it should be, I suppose I can write documentready function at the earliest possible .wait ? i.e., after adding a .wait right behind .script(&#039;jquery.validate.js&#039;) ?

Also, once again, please could you post some links that you could be helpful and save you the hassle?

Thanks</description>
		<content:encoded><![CDATA[<p>Hi, </p>
<p>Many thanks for the brief insight! I will keep it in mind. </p>
<p>Also, I really think that there are a lot of novice labjs users who are confused like I&#8217;ve been. Could you please post some links to examples of LABjs used with various javascript libraries like jquery , yui etc. ?</p>
<p>I had a very hard time coming across examples of labjs on the internet. <img src='http://getiblog.2static.it/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /><br />
Also, I thought I was doing the right thing loading dependent group of scripts (e.g., jquery.validate, jquery.form, etc.) into a single .block (I&#8217;ll use .wait now on though) that would load after the jquery library is loaded.</p>
<p>Looking at your example above, I think I still am not 100% sure.</p>
<p>Due to the dependency of validate and jquery form upon jquery, I assume the following would be efficient &#8211; I am assuming that validate and form will both loading in parallel after jquery.js finishes loading :<br />
&#8211;<br />
$LAB<br />
.script(&#8216;jquery.js&#8217;).wait(function(){$LAB.script(&#8216;jquery.validate.js&#8217;).wait().script(&#8216;jquery.form.js&#8217;)})</p>
<p>But you stated above:<br />
&#8211;<br />
$LAB<br />
.script(&#8216;jquery.js&#8217;).wait().script(&#8216;jquery.validate.js&#8217;).script(&#8216;jquery.form.js&#8217;).wait();</p>
<p>which looks much simpler than expected! So if I am assuming it wrong and the example you&#8217;ve given is how it should be, I suppose I can write documentready function at the earliest possible .wait ? i.e., after adding a .wait right behind .script(&#8216;jquery.validate.js&#8217;) ?</p>
<p>Also, once again, please could you post some links that you could be helpful and save you the hassle?</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: getify</title>
		<link>http://blog.getify.com/2009/11/labjs-how-to-deal-with-inline-code/comment-page-1/#comment-487</link>
		<dc:creator>getify</dc:creator>
		<pubDate>Mon, 02 Aug 2010 13:03:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.getify.com/?p=122#comment-487</guid>
		<description>@Arun-
Glad you got the jquery.validate issue squared away. But please also be aware that your technique of using $LAB chains nested inside of .wait/.block calls is less efficient. You should try to write it as all one big chain with .script and .wait calls interspersed. For instance:

$LAB.script(...).wait(...).script(....).script(....).wait(...)......

You&#039;re doing stuff like this and it&#039;s less efficient:

$LAB.script(....).wait(function(){   $LAB.script(....).wait(...)....   })......

Do you see the difference?

Secondly, the &quot;.block&quot; is a deprecated name for &quot;.wait&quot;, so you should always use .wait, not .block. And make sure you&#039;re using LABjs 1.0.2rc1, which is the latest stable available version.

Also, do *not* assume that a $LAB.wait() call is equivalent to waiting for dom-ready. The dom-ready event is entirely separate from the dynamic loading of scripts, so you may have sometimes where the dom-ready happens before the scripts finish, and other times the reverse. So you should always use $(document).ready() to protect any code which relies on the presence/readiness of the DOM.</description>
		<content:encoded><![CDATA[<p>@Arun-<br />
Glad you got the jquery.validate issue squared away. But please also be aware that your technique of using $LAB chains nested inside of .wait/.block calls is less efficient. You should try to write it as all one big chain with .script and .wait calls interspersed. For instance:</p>
<p>$LAB.script(&#8230;).wait(&#8230;).script(&#8230;.).script(&#8230;.).wait(&#8230;)&#8230;&#8230;</p>
<p>You&#8217;re doing stuff like this and it&#8217;s less efficient:</p>
<p>$LAB.script(&#8230;.).wait(function(){   $LAB.script(&#8230;.).wait(&#8230;)&#8230;.   })&#8230;&#8230;</p>
<p>Do you see the difference?</p>
<p>Secondly, the &#8220;.block&#8221; is a deprecated name for &#8220;.wait&#8221;, so you should always use .wait, not .block. And make sure you&#8217;re using LABjs 1.0.2rc1, which is the latest stable available version.</p>
<p>Also, do *not* assume that a $LAB.wait() call is equivalent to waiting for dom-ready. The dom-ready event is entirely separate from the dynamic loading of scripts, so you may have sometimes where the dom-ready happens before the scripts finish, and other times the reverse. So you should always use $(document).ready() to protect any code which relies on the presence/readiness of the DOM.</p>
]]></content:encoded>
	</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:15:43 -->