Wednesday, July 27, 2011

JavaScript in Web Application

How important a role Javascript plays in a web application? Do we really need to have Javascript to write a web application? In old days, at one point of time, Javascript became the bashing child because of the security holes in the browsers, especially cross site scripting. However the world has moved a lot after that and we have browsers which are more secure. Though still there are strategies in many web application in many organizations to handle the things when Javascript is turned off. why?
Look at web2.0 revolution and one of the most important technical element of it is AJAX, whatever it stands for. People throw the term like the drop of a hat. And don't surprises if someone says that we need AJAX but we should have the capability to handle non Javascript environments. Pretty strategic vision. AJAX is nothing but one of Javascript components. The bottom line is that we cannot have rich web applications if we do not have Javascripts. HTML is a good but dumb guy. Javascript is the one which bring spices in the life. So if you are reading this, I would request you to convince your customer that why Javascript is important. It's a must for doing meaningful rich applications. If still there bureaucracy wants to play safe (they think so), than increase the project duration by at least 3 times. (I am not joking). Why?
Suppose we have an application where we have a drop down choice and based on each choice we want to present different sets of form elements to the user. I will not tell how you can do it with Javascript. But with plain HTML for each change in the choice you have to go to server and render the new HTML page and send it back to user. And if the user is one of the confused guy like me, I am sure your server has a good amount of work to do.
Hopefully now you have decided to use Javascript. If not, go back and read again. So what Javascript helps in doing in a web application? Javascript provides the dynamic nature to the application. Hiding and showing controls based on certain selections. AJAX to provide the on time behavior and interacting with server in a very light weight fashion. When the HTML is rendered in a browser it is kept as a DOM structure in the data model. With Javascript, this dom model can be manipulated which in essence means that you can change everything in the page. Validations are another important thing that Javascript achieve. Javascript is a pure client side thing, so validations at client side helps in server trips. And you can write any sort of complex behavior.
Okay so you have decided to adopt Javascript in your application and now what next. Get a book on Javascript or look into one of the tutorials on net and start implementing Javascript functions. Welcome to the world of browser incompatibilities. People who come from portable language background suddenly find themselves in murky water. A lot of time is spend in writing Javascript, and without the kind of support of IDE for the other programming languages and debug capabilities. (Firefox has got one, so you might want to have a look at that). And your script runs fine in Firefox and than behaves unpredictably in other browsers. What to do?
Browser incompatibilities are a major area of concern in Javascript development. And it's not just between Firefox and IE, the different versions of IE do behave in a different way. Microsoft has a different take on many things in this area. It's good, gives the programmers the job opportunities. If Microsoft would not have been there, the world would not have been so interesting. so What's the solution.
There are many good folks who faced this problem and took it as a challenge and came up with frameworks which handled the discrepancies in a transparent way. So if you have decided to go for Javascript, than adopt one of those frameworks, which will make the life easier. The more important once are jQuery, extJS, Dojo, YUI etc. These frameworks internally handle the browser incompatibilities and provide a unified set of api's to work with.

No comments:

Post a Comment