WSO2Con 2013 CFP Banner

The AJAX Experience in Web Applications - Chamil Thanthrimudalige

Archived Content
This article is provided for historical perspective only, and may not reflect current conditions. Please refer to relevant product page for more up-to-date product information and resources.
Discuss this article on Stack Overflow
By Chamil Thanthrimudalige
  • 1 Mar, 2007
  • Level: 
  • Reads: 4898
AJAX is used by WSO2 WSAS (Web Services Application Server) to implement its administration console. In this interview, Chamil talks about the pros and the cons of AJAX technology.
Chamil Thanthrimudalige
Software Engineer
WSO2 Inc.
Chamil Thanthrimudalige, a Software Engineer at WSO2, is a core contributor to the AJAX management console. He is also an Apache committer for Axis2/Java.  Oxygen Tank (OT): Chamil, can you give us a brief introduction to AJAX? Chamil: AJAX is an acronym for Asynchronous JavaScript and XML. Data is retrieved from the server as XML and then rendered on the client side using an XSLT style sheet. While the data is being loaded the user interface remains responsive since the data is loaded Asynchronously. That is, when the data request is made, the request invocation is done on a separate thread from the JavaScript's current execution chain. So the script keeps executing and the user interface stays responsive for additional user input or commands.Actually, it was Jesse James Garrett who first used this acronym in public, in February 2005. When Garrett was asked why he coined the phase his response was “I needed something shorter than 'Asynchronous JavaScript + CSS + DOM + XMLHttpRequest' to use when discussing this approach with clients.” OT: Can you elaborate on the benefit of using AJAX in Web applications? Chamil: It can create more interactive Web applications than those using static HTML. The aim of this technique is to make Web pages more responsive. Since only the data layer is retrieved from the server when the user makes a request, the page loads a lot faster. Additionally, the data retrieval happens behind the scene, the frequently accessed data can be preloaded and cached.The success of GMail and other Google products based on this technology acted as a catalyst for the popularization of AJAX. Other notable examples are Flickr and Amazon’s These massive success stories created a launching pad for the technology. OT: So is AJAX all good news for Web applications? Chamil: Not really. It has a bundle of problems that comes along with it. To start off with, cross browser usage of JavaScript causes issues due to that fact that all vendors do not implement every thing the same way. Also the response-time issues when the network is unreliable can cause inconsistencies in a browser based UI. There is also the fact that search engines don't index AJAX based Web pages very well.There was also this issue where you also loose the functionality of the 'Back' button and the book marking of pages from the browser because even when the content is changed the URL does not change and thus no entry is made in the history.However, there are a host of third party AJAX libraries that will take care of most of these issues automatically. Something that has not been addressed a lot so far is the issue with the site indexing, but that too can be tackled with a combination of Web page loads to do some work and using AJAX to do the other operations once you are in a certain page. OT: Do you have any of your own tips or tricks to deal with these issues? Chamil: Hm...a few. Since the work is happening behind the scenes, we give an indication to the user that some thing is actually processing. Otherwise the user will be disoriented and confused since he does not see any change after doing some thing.Since the user should be able to click on the 'Back' button of the browser and go to any previous page, which he would reasonably expect to go to, we use a library to add this capability to our Web site. We avoid the use of IFrames in the code to avoid problems with libraries that provide the 'Back' button functionality. OT: How is AJAX used inside WSO2 WSAS for Java? Chamil: The WSO2 Web services Application Server (WSAS) for Java has an administration console that is created using AJAX based technologies. We use the XMLHTTPRequest object to send a request to the server in the form of a SOAP message to which we get a SOAP message as a response.One of the interesting things that we have done with AJAX is our System Statistics page. Which is refreshed periodically by loading data in the background. All the old data remains in the cache and only new data is loaded and used to re-render the graphs.We have also built a dynamic client generator, which uses the WSDL of the service to generate a DHTML client for invoking the service within WSAS. OT:Why did you use the SOAP based approach? Chamil: We have taken this approach because we believe that this method of working with AJAX will provide us with the best possible application interface. In addition to the browser based administration console, a non Web based version could also be built without any changes to the server API. With the emergence of the WSO2 WSF/AJAX stack, we will eventually be able to access the full power of Web services within browser. The use of SOAP gives us the ability to use WS-Security, WS-Reliable Messaging, etc. We also get to use the power of WSDL when doing stuff like dynamic client generation. OT: So is AJAX suitable for all Web applications?Chamil : It depends. No one would want to put in the extra effort needed to build an AJAX application if they only want to show stuff on a few HTML pages...As site indexing is a major issue with AJAX based approaches, and you want your Web site to be indexed, you will have to use the conventional HTML pages. If you really need to have some AJAX features as well as being indexable you can build a hybrid.The best place to use AJAX is when you are building a system that a user would login and access the site for a long time. Very good examples are management consoles and email applications. With AJAX based management consoles you can pre-load data in the background as well as have graphs and statistics pages that are refreshed periodically. Initially it was Gmail and now even Yahoo mail is using an AJAX based system to give the users a more rich user experience.AJAX can open up a lot of wonderful options, but you need to analyze the situation first, rather than blindly getting on the AJAX band wagon.OT: Thank you very much Chamil. More Information: Web Services with AJAX - Why and How by Samisa Abeysinghe