Monday, March 15, 2010

Javascript : A Primer

Javascript, a client side scripting language mostly used in Web Browsers earlier, is now spreading its wings to other platforms like TV (Yahoo TV Widgets Platform) and Mobile (Palm WebOS and PhoneGap for cross platform mobile development).

Javascript became highly popular after the advent of Ajax. There are number of popular Ajax libraries used widely in most of the Web Applications.

The list includes the likes of
1. jQuery by John Resig (
2. Yahoo User Interface or YUI (
3. Dojo (
4. Prototype js (
5. JavaScriptMVC (

Javascript can be inserted into a web page by using "script" tag.
Traditionally, all the script tags were placed in the head section so as to keep all the external files references(js + css) in one place. However, including all the script tags in head section would mean that all the script files have to be downloaded and parsed and interpreted before the page starts rendering which can easily cause delays and performance of the website takes a beating. So the ideal place for the script tags is in the body section towards the end of the page.

Apart from loading scripts, users can embed javascript code using script tags. For xhtml pages the ideal way to embed a javascript code is to wrap it in the CData section. CData sections are used to indicate the text not intended to be parsed. Putting Javascript code into external files have its advantages over inline code in terms of maintainability (as the code is independent of markup), caching and it does not require the use of xhtml or comments hacks.

Javascript will continue to evolve at fast pace and even faster when most of the features of HTML5 are rolled out.