Monday, April 2nd, 2007

twoBirds Lib 2.0 Released

Category: JavaScript, Library

twoBirds Lib 2.0, a library that handles on-demand loading problems, has been released by Frank Thuerigen.

It works asynchronous and allows out-of-order execution of JS code. JS objects can recursively load other JS objects.

Take a look at the prototype to see it in action:

In the “user” field top right enter a character combination and hit return to enter… in the menu click on “communication” and then “chat”… enjoy your chat. A closer look using firebug etc. will reveal that all element parts are loaded separately, simultaneously and out-of-order, on-demand when you click on a link.
The system itself ensures that elements are being displayed once all the necessary files have loaded. Note: IE users may have to add this site to the list of trusted sites, since login requires a cookie. All demo windows are accessible without login.
There is no more loading after the first display of an element, all data and code was cached and on re-selection displayed right away causing no server traffic. The chat will periodically retrieve new lines, of course…

Example Code


  1. application.index_body = {
  3.    init: function (pDivId) {
  4.    tb.element.require(
  5.    â€œ[ [ ‘css’, ‘application’, ‘index_body’ ], ” +
  6.    â€ [ ‘tpl’, ‘application’, ‘index_body’ ], ” +
  7.    â€ [ ‘js’, ‘tb’, ‘effect.fadeTo’ ] ]”,
  8.    â€˜application.index_body.display( “‘ + pDivId + ‘” )’ ,
  9.    true
  10.    );
  11.    },
  13.    display: function (pDivId) {
  14.    var myHtml = tb.loader.tplget(’application’,'index_body’);
  15.    tb.div.replace( pDivId, myHtml );
  16.    tb.element.require(
  17.    â€œ[ [ ‘js’, ‘application’, ‘menu’ ], ” +
  18.    â€ [ ‘css’, ‘application’, ‘menu’ ], ” +
  19.    â€ [ ‘tpl’, ‘application’, ‘menu’ ], ” +
  20.    â€ [ ‘js’, ‘application’, ‘user_greeting’ ], ” +
  21.    â€ [ ‘css’, ‘application’, ‘user_greeting’ ], ” +
  22.    â€ [ ‘tpl’, ‘application’, ‘user_greeting’ ], ” +
  23.    â€ [ ‘js’, ‘application’, ’submenu’ ], ” +
  24.    â€ [ ‘css’, ‘application’, ’submenu’ ], ” +
  25.    â€ [ ‘tpl’, ‘application’, ’submenu’ ], ” +
  26.    â€ [ ‘js’, ‘application’, ‘window’ ], ” +
  27.    â€ [ ‘css’, ‘application’, ‘window’ ], ” +
  28.    â€ [ ‘tpl’, ‘application’, ‘window’ ] ]”
  29.    );
  31. ‘toprightcontainer’ , ‘application’, ‘user_login’ );
  32.    }
  34.    };

Posted by Dion Almaer at 7:43 am

3.8 rating from 23 votes


Comments feed TrackBack URI

I´d like to add, that my HP will be replaced with something valid ASAP including download links for the libs. Until then, please contact me using the following email: frank dot thuerigen -at- phpbuero anotherDot de
Thx and sry for the inconvenience when watching the old HP.

Comment by Frank Thuerigen — April 2, 2007

@Frank – I had a quick look at your code this morning after your email yesterday. I couldn’t work out what I was looking at. :-) Any chance you can write up your technique? A bit of background info might help people understand it.

Comment by Dean Edwards — April 2, 2007

@Dean – of course I will. There will be user documentation (2 pages no more), system documentation (that will be more) and a history of wrong solutions i have tried and dumped (little hint: all exec() solutions for js code are in the trash bin)… I have given away my HP design because it looks like its going to become stressy here soon ;-)
Cheers Frankie

Comment by Frank Thuerigen — April 2, 2007

BTW V1.0 was proof-of-concept, V2.0 (thats where I am now) is stable for production, V3.0 will be optimized and clean code. Its still some way to go ;-)

Comment by Frank Thuerigen — April 3, 2007

@ Dean – since it boils down to a couple of simple things, I can answer your question about the technique here:
(1) after all tries and failures: it is not a good idea to load JS via xhr and eval() it – simply because you cannot properly debug it. Inserting JS and CSS is done by putting it in the .
(2) you need a naming scheme to check whether an object has loaded. E.g. I load a JS file named and located: /twobirds/modules//js/.js – the object contained in this file must be named . since the library waits for this to show up in the global scope in order to determine whether an object has loaded and is available.
(2) to check whether CSS has loaded properly I use document.stylesheets – it is pretty much cross-browser with a MS switch in it.

It is funny – after all the tries and complicated approaches it really boils down to this. The rest of the lib is nothing new. Its all about the simple solution and the structural concept.
Cheers, Frankie

Comment by Frank Thuerigen — April 5, 2007

putting it in the …. head. The software here killed the tag.

Comment by Frank Thuerigen — April 5, 2007

same here:
contains an object named

Comment by Frank Thuerigen — April 5, 2007

There will be user documentation, system documentation and a history of wrong solutions i have tried and dumped.

Comment by ingilizce tercume — August 2, 2007

There is a blog available online…

Comment by Frank Thuerigen — October 22, 2007

Leave a comment

You must be logged in to post a comment.