As I’ve been poking around in YUI3, much to its annoyance mind you, since nobody likes to be poked, I’ve notice something very different about it. With many javascript libraries, you get the sense that the authors would very much like you to give up all work in other libraries and join the “one true faith” of this library. Instead of using your own code to do drag and drop use OURS. Instead of using jQuery’s AJAX, use OURS. Instead, I get the impression that YUI3 is much more pragmatic in its purpose. Instead of chaining you to one way of doing things, it has this idea of “bringing in” libraries and functions when you actually need them, instead of dumping let another few milliseconds onto your site’s pageload at the beginning. This really frees you up because you can just load the bare bones set of code you need to get things going, and pull in other libraries on demand. It’s almost like LOD for javascript. LOD is “level of detail”:
In computer graphics, accounting for level of detail involves decreasing the complexity of a 3D object representation as it moves away from the viewer or according other metrics such as object importance, eye-space speed or position. Level of detail techniques increases the efficiency of rendering by decreasing the workload on graphics pipeline stages, usually vertex transformations. The reduced visual quality of the model is often unnoticed because of the small effect on object appearance when distant or moving fast.
So LOD for javascript would be “increasing complexity” or “loading more js” only when you believe the user is about to need it. YUI3 with it’s loader functionality really makes this easy to do. However it is a seductive thing as well. Instead of loading a bunch of URL’s at the beginning of a page, you are essentially invoking code via a single word or phrase. This invocation is further empowered by the fact that you can create your own dependencies. Perhaps you have your own custom code A that needs B and C in order to work. You just build up an expression that codifies this and whenever you ask for “A” YUI3 will secretly go get B and C – make sure they are there – and then bring in A with it’s cadre of friends.
Are you yawning yet? Bored? Got grab a snack and come back.
Ok, let’s continue. The amazingly cool and seductive aspect of this is that you will find yourself wanting everything to be brought in via this “invocation”. Much like a wizard, you want your Green Spells and your Blue Spells in one handy book. YUI3 doesn’t care if the code you want to bring in is YUI3 code, YUI2, jQuery, Ext-JS, or your own bubbling concoction of javascript wizardry. Couple this with the fact that you DONT have to load all that junk when the page loads initially, you get a very powerful incentive to use all kinds of libraries to suit your needs, since you don’t have to pay the price of admission until someone actually looks like they will want to USE that code.
What I find very ironic about this is that instead of banging you over the head with “use our stuff only!” you find you want to use YUI3 — even it if is only for this awesome ability to pull in code whenever you need it (and construct clever dependency trees for you). This makes YUI3 very attractive for integrating into your existing javascript framework. Say you use jQuery. Keep on using it. Just load it up via YUI3 and dont bring in all those jQuery plugins you’ve been using until you really need em.
It’s the first javascript library that I’ve seen that actually enhances the utility of your existing library! Plus, YUI is pretty darn fast in and of itself. You may find that once you took a sip of the YUI-Aid that there’s another trick it might do that you want. Perhaps in the YUI Gallery you discover something cool (like YQL). I know I’m not just blowing smoke here because other people are beginning to realize this as well. Caridy Patino as written a wrapper for YUI2 in YUI3. What this means is that the entire YUI2 library is now a full fledged component in YUI3!
So, my point is this. Instead of many js library’s implied NIMBY (Not In My BackYard) where you are discouraged from using mixed code, YUI encourages it by wrapping it with a handy framework to help manage it. I wouldn’t be suprised if someone writes a wrapper function for jQuery plugins. It would be pretty easy since YUI could look at the plugin, say it itself “Oh, I need jQuery 1.3.1 – just a minute while I fetch it” then happily turn on the plugin. So instead of an empty “backyard” with just one JS Lib nervously sipping that cup of Uncle Joe’s punch, you have a whole Backyard Barbecue of Lib’s all happily talking to one another and in turn making your website users happy as well.
Give YUI3 a try and see what I mean!
And invite me to your next Website Barbecue…. YUM!
