Thursday, 22 April 2010

How to choose JavaScript framework

You have probably found many articles describing what are requirements that one JavaScript framework has to have. Some of them are (they are not listed in any particular order):
  • list of supported browsers
  • documentation
  • community
  • intuitive API
  • speed
  • extensible
and so on.

But many of this articles fail to mention one of the most important things. This article will introduce you to one of the most fundamental thing in cross-browser scripting - feature testing technique.

Basically, there are two browser scripting techniques (as far as I know):
  • browser detection
  • feature testing
In short - browser detection relies on user agent string to detect browser and then scripting is done based on browsers features. The problem with this approach lies in unreliable user agent string. Many browsers send wrong user agent string, but things are even worst - detecting rules are far from perfect. Sometimes, same browser is being detected differently depending on OS (for example, IE8 is being detected as IE6 in Windows Vista, because it's user agent string contains number 6). That way, when new browser comes out on the market, new version of browser detection has to be made. It's constant struggle with time and new browsers.
Better approach is to use feature testing. Basically, you test what browser supports and provide fall-back in cases of lacking support or of feature not working correctly. This approach is better from browser detection because it does not rely on user agent string, instead of that it test what is browser capable to do. This way, when new browser comes out, no new version of feature testing has to came out (everything is tested the same way) and that makes it future proof. Even more - it will work on unknown and rare browsers.

There are some great articles about feature testing:

Now, before running to Google and start searching for JavaScript frameworks that are based on feature testing - STOP.
Before choosing JavaScript framework you should learn language upon which framework is based on. Your starting reference should be ECMA-262 standard, you can download it here:

Also, you should learn HTML and CSS specifications which can be found at W3C web page.

Any questions regarding browser scripting you can ask at: 

Sometimes it's not so pleasant place because of some bad attitudes and not so pleasant language, but you should use your Zen skills and ignore people you don't like. There are some people there with great knowledge and pleasant language.

At this point you can search for JavaScript frameworks that are based on feature testing. But you'll get disappointed because most of today's modern JavaScript frameworks still relies on browser detection.

Many of you probably uses JQuery. JQuery from version 1.3 claim not too use any form of browser detection. Well, that not so true - it uses object inference to detect browser (
History has shown that JQuery authors weren't so convinced that feature testing is right way, but recently have shown some wisdom, although not entirely. 

But then, you should ask yourself, why should I use something that they "borrow" from someone ... why not use framework from people that were feature testing evangelist from the start. Well, there were some frameworks, but me personally didn't find them useful.

Recently, a new JavaScript framework started to show up, it's called My Library ( I think, maybe it's not yet ready for real usage, but you should keep an eye on it. It's maintained by David Mark, man of big mouth (well, that's his way of doing marketing :) ), but man of great knowledge. Despite the fact that most of the time he just spits on other mayor JavaScript frameworks, there have been some great technical reviews which can be found on JavaScript Google group. Me personally would like more technical speech from him, but I think My Library speak for it self. Check for it's speed tests and task tests, try them in many browsers and see for yourself.

Probably, some of you will comment about his widgets and they design, but you shouldn't (they will look cool in near future). JavaScript framework shouldn't be chosen based on nice graphic. There are graphical designer to do nice graphic on one hand, on the other hand do you really want to use same widget look as many other people? I don't want, I want to have unique design.

JavaScript framework should be chosen based on following things (not in any particular order):

  • feature testing
  • small in size
  • speed and task tests on slow machines and slow JS engines
  • future proof - so you don't have to upgrade every time new browser version comes out
  • intuitive and self-describable API 
  • good documentation with advanced examples and good explanations
  • community
  • useful plugins and widgets
  • quality
  • stupid proof - that means, framework and it's author should stop you from doing stupid things (learn instead)

My Library JavaScript framework is close to official 1.0 release (I'll write review after it's release). Soon, it's page will have new design, it widgets will look nice, documentation is getting finished, new widgets are on their way ... so, there is no need for you to just stand there and wait. Try it!

No comments:

Post a comment