Labels

Monday, August 31, 2009

Why not AJAX

This article will try to shed some light on what AJAX really is, where you should use it and where you shouldn't

 

Logic Behind AJAX:

 

·          At the heart of the AJAX method of communicating with the server lies the AJAX engine.

·          This is nothing more than some JavaScript code that instantiates and uses the XMLHttpRequest object.

·          This is a JavaScript object that allows sending, receiving and processing HTTP requests to and from the server without refreshing the entire page.

·          In AJAX-powered applications, HTTP requests for data can be made completely in the background, without the user experiencing any interruptions. The XMLHttpRequest object was implemented as an ActiveX object in Internet Explorer, and has later become a native JavaScript object in most modern browsers (FireFox, Safari).

·          Although adding an extra layer to any kind of model should add to the response time, this is an exception.

·          Through the use of this new layer – the AJAX engine – response time shortens and the user interface seems much more connected to the application logic. Moreover, the user no longer has to wait around for the page to load.

 

 

Why use AJAX?

 

·          Building a web application that employs AJAX is more difficult than building it the classic way.

·          The decision whether an application would benefit from using AJAX or not is entirely up to the developer.

·          Here are a few hints to help you take the right decision.

 

 

The Benefits of AJAX -

 

To help you decide whether AJAX is for you or not, here are some of the advantages it has over classic web development techniques:

 

More Responsive

The interface is much more responsive, as only a small part of the page is transferred at a time.

 

Multiple Connection Threads

·          In a classic web application, when the web server sends a web page to the browser, it can use multiple connection threads to speed up delivery.

·          However, this happens for content only – what is between the <body> tags. All script and CSS files linked in the page's <head> section are transferred using only one connection thread, which diminishes performance.

·          With AJAX, you only have to load the basic scripts and CSS files, and request the rest as content, through multiple connections.

 

Waiting time is reduced

Waiting time is reduced – the user can still work while the data is being submitted

Fails graciously

·          If a page section encounters an error, other sections are not affected and the data already entered by the user is not lost. This way, the application fails graciously, without causing head-aches for the users.

 

Traffic is reduced

·          Traffic is reduced considerably – The bandwidth usage is most likely to decrease.

 

 

 

The Disadvantages of AJAX

 

As with most new web development techniques, AJAX has its critics. There are a couple of disadvantages that need to be considered before considering an AJAX-based solution:

 

 

Increase in development time and costs

·          It is usually considered more difficult than building a classic web application, because of the mixture of technologies and the special concern about everything going smoothly. However, because it is dealing with relatively known technologies, AJAX is not rocket science.

 

Available frameworks and components still need to completely mature

·          Although AJAX relies on existing and mature technologies like Javascript, HTML and CSS, the available frameworks and components still need to completely mature. Tools like the Dojo toolkit or the Rico framework are just a milestone on this long road. More frameworks that target a specific area are likely to come your way

 

Security and user privacy

·          Not all concerns regarding security and user privacy have been answered. This fueled a wave of criticism about how safe is the AJAX way of building applications. Earle Castledine points out some of his concerns regarding user privacy in this article from DevX.com.

 

Existing page conflicts – Back button

·          Using AJAX to asynchronously load bits of content into an existing page conflicts with the way we are used to navigate and create bookmarks in modern browsers. Because viewing some part of the page information no longer corresponds to a newly loaded page, the browser history and bookmarks will not be able to restore the exact page state. Also, clicking the Back button in a browser might not have any effect, since the URL was unchanged (even if parts of the page were changed). To overcome these problems you must implement a way to save the current page state so that it can be restored later on, when called from a bookmark or from the browser history.

 

Google cannot index it

·          AJAX is not meant to be used in every application. One of the main reasons for this stays in the fact that Google cannot index it. Consider this basic example that Alexandru Costin, the co-founder of InterAKT Online, pointed out: "Suppose you are building an e-commerce site. A complete AJAX application would be a mistake because search engines won't be able to index it. And without a search engine, a site won't be able to sell products." Keeping this in mind, a much better idea than creating complete AJAX applications would be to scatter AJAX features within the application.

 

Support for JavaScript or the XMLHttpRequest object

·          The biggest concern with AJAX is accessibility. This is because not all browsers (especially older ones) have complete support for JavaScript or the XMLHttpRequest object. Some of the visitors do have browsers with the required features, but they choose or have to turn off JavaScript support. When you design the application you must make sure that a fail-safe solution exists for those users, so it can be accessed by anyone. Further more, the way to access and use the XMLHttpRequest object in Internet Explorer and other browsers is different, which leads to a fork in the code and the need to treat each case separately.

 

Multi Server

·          The last disadvantage lies in the actual XMLHttpRequest object itself. Due to security constraints, you can only use it to access information from the host that served the initial page. If you need to display information from another server, it is not possible within the AJAX paradigm.

 

 

 

 

Regards,

Arun Manglick || Technical Leader || Monetrics - MDE || 620

 

No comments:

Post a Comment