javascriptjqueryhtmlfeedburnerlabjs

LABjs Problem With Loading Script


I'm using labjs to load my scripts. I've got a script from feedburner which shows the lastest posts from my blog in HTML from my rss feed. The code from feedburner is and works just fine, showing all the posts in html:

<script src="http://feeds.feedburner.com/Goonerhood?format=sigpro" type="text/javascript" ></script>

I'm trying to load the same script using labjs, but it's not showing anything. Here's my code:

<script>
   $LAB
   .script("http://feeds.feedburner.com/Goonerhood?format=sigpro");
</script>

Any suggestion where I'm going wrong?


Solution

  • The problem is that that script is all about document.write, which cannot be used (well, should not be used) when you're loading a script with any sort of dynamic, asynchronous technique.

    The document.write function can be used when a script is imported with a <script> tag for two reasons:

    1. The browser executes the script immediately on its being available to it (i.e., when the server returns the script to the client), blocking all other activity until the script is done;
    2. The DOM is not finished yet at the point something like (1) happens, so calling document.write appends content to the in-progress DOM.

    When you load a script asynchronously, the script won't be executed until after the DOM is completed. At that point, a call to document.write implicitly calls document.open, which on an already-built page will blow everything away.