AJAX

AJAX is a part of RIA, that has been heating up for some time now. Even though with newer and more richer technologies coming up like Flex, Silverlight, AJAX still remains the most commonly used option. I attended a workshop on AJAX today which had the participation was from a set of Senior Developers and Technical Architects who have been either working on AJAX or plan to use that. Below is a brief summary of the workshop.

Objectives

1. Compare AJAX with web 1.0

2, AJAX fundamentals

3. XHR and its role in AJAX

4. JavaScript and DOM

  1. AJAX and Web 1.0

5. AJAX frameworks – DWR, GWT, RICO and YUI

6. Technical aspects of AJAX in a project

Why AJAX?

  • Conventions Web applications handle data and presentation together and hence that leads to slower bandwidth
  • Faster response time is now desired
  • Enhanced Usability – moving close to Rich Internet Applications
  • Trying to do “Mashups” – bringing various Services together and bring in some meaning to the data

In the past, Sun proposed to use Applets for any kind of RIA stuff, but did not kick-off. Macromedia came up with ActionScript that can be used to create Flash files and help you more interactive content. Moving from a proprietary language to Open Source and more recently Flex is how Adobe acquired Macromedia bring this to developers. DHTML with IFrames was another option – but again is “more of a hack”, and is mostly suited for client-side richness.

Soon, people came up AJAX (Asynchronous Javascript And XML) – which was based on some of the existing frameworks and could be easily integrated with existing code/applications.

Next up was a quick demo of using the XHR object in a JSP and the intent was to show how we can use well constructed HTML v/s XML and then rendering the same on the client.

We moved to a JavaScript 101 and how can we quickly setup and re-use JavaScript and DOM and how to modify the styles and DOM object etc. Some of the very basic stuff, but good one. Very nice quick start demo on how to use the AJAX quickly on JavaScript. We moved on the most talked about issue in a Web 2.0 issue – History and Bookmarking. In a typical web 1.0 application, as we are moving from one page to another, the browser by way of changing URL keeps track of your navigation. But, with the XHR object, no changes to browser URL happen and “KPOW”. Now is the break time, but we are going to come back and see how this problem can be solved.

It was shared that RSH that supports the history with the browser. To understand the very basic, we need to change the browser URL on every request. But, that is something that we do no et out of the box. Some custom code has to be written. This is one way of talking to the browser, but we also need to write listeners for the changes to the browser URL. This way, we can communicate to back and forth to/with the browser. Looking quickly at the RSH library, it seems like a good starting point.
AJAX Cons

  • Increased complexity on Server as well as client
  • Dependency on JavaScript – you need to have advanced JS developers to highly optimize JS code
  • XHR is not yet standardized by W3C
  • Backward compatibility with some of the older browsers

Web 2.0

Web 2.0 is about creating applications which can be integrated with other applications such that users can use data in a anyway they want to view and use it. Web 2.0 application can be one that makes use of data from other applications which offer data as service and simply provide you a combination of all such services. In other words Web 1.0 was “I will create something and then provide that to the user”, while Web 2.0 talks about “I will create a service that someone else can offer to their customers”.

Challenges of writing RIA applications

  • How much code for working with XHR requests
  • How many clients do we need to handle
  • What is the data-format that we need to work with
  • Exposing Business Logic to the client

Hence we need to choose a Framework!! – we have way too many @Ajaxian.com. A framework needs to worry about:

  1. Server side – What kinds of clients do we need to handle
    1. JSF, DWR, GWT etc
  2. Network – How many kinds of clients do you need to provide service to
    1. Jason, XML, SOAP, RSS
  3. Client side – Need to deal with the data and provide that richness to the client
    1. DOJO, YahooUI, script.aculo.us, RICO

A survey was conducted in 2006, that shows what various AJAX libraries were being used

Focus on Server side of an AJAX application

Deep dive on DWR or Direct Web Reporting

Some insights:

  • Is a Java based technology to handle client-based AJAX requests
  • Uses an XML-based configuration that helps creating run-time JavaScript and gets exposed on the client-side
  • Exposes the Java object as Stubs on the client. You can then make calls to the stub and get data from Server
  • Has the capability to expose all the functions of an Object on the client
  • Takes care of the Server side aspects like using the same POJOs and passing on to the client. The Client can then handle the objects as they feel like
  • Offers integration with existing frameworks like Struts and Spring

There were a few more things, but not so much that I can write about. Hope you find this article useful.

3 thoughts on “AJAX

  1. I used symfony’s native helpers to write all of the ajax calls for clipmann. Symfony does REALLY make it EASY for anyone to mess with ajax like it aint nothing!.

    You CAN shoot yourself in the foot with it!, too many helper calls could be dirty!, and sets you in some logic deadlocks!, but its all good, if you keep it simple STUPPIIIEEEED.

%d bloggers like this: