Working with Ajax
I developed some components that interacted with the server in an AJAX-like manner (posting to a servlet, registering a callback function that would process the output from the server). I ran into a few issues and spent some time thinking about AJAX development.
I noticed some tight-coupling for calls that returns HTML content which has Javascript due to not loading of JS libraries retrieved via AJAX. Some calls were getting some HTML content that required JS libraries for launching popups or DHTML manipulation. The HTML content came with the required JS libraries but the browser (IE 6) was not loading these libraries. As a result the calling page had to load the libraries that were used by the HTML content retrieved thru AJAX.
I didn’t like this because I wanted to be able to encapsulate my component in some form, shape or manner and then have it used without having to determine how are these components coupled and enforcing this coupling. It looks like at the current stage of development component encapsulation is not implemented in AJAX.
One problem this causes is that the component’s future development is pinned. You cannot add more functionality to it because the JS libraries which will implement this functionality will have to be imported in the pages using the AJAX component. You will have to document the dependencies between the AJAX component and the pages calling it, reload the libraries in the dependent pages and re-test them. Big effort…
Note: There is a work-around: getting the JS libraries and adding them to the document in a <script> tag. This would cause the browser to parse the JS required by the component. However this would require 2 calls: one to get the libraries, add them to the document in a <script> tag and another one to pull the component that uses these libs.
Also, it is possible that future browsers will determine if JS libraries are retrieved thru an AJAX call and parse them.
The concept of application on one page is a bit flawed. The problems posed by a browser’s refresh button will add to the problems of the back button and so on. The current AJAX client is missing some important functionality (it is not transactional for example) and probably due to the variety of JS implementations in browsers it will always miss this functionality. Drawing a boundary between what logic falls on the client and what falls on the server is an extra effort. App versioning and the browser’s JS cache pose some interesting problems too.
I wonder what will happen to an application written in AJAX and to its code base once W3C will put out HTML 4.01 (which among other things will separate the data from presentation and style)? Will these apps suddenly become obsolete? Probably yes.
The biggest drawback of AJAX is that AJAX is currently under-developed. Everything revolves around the return status of the http request. There are some libraries out there (such as DWR – Direct Web Remoting) and some frameworks are being developed but otherwise AJAX is under-developed. The plumbing is being developed by ear for now. It is possible that Microsoft will come out with their own plumbing for asynchronous client-server communication. It is likely the W3C will expand this technology as well. The danger that your current code base will grow obsolete is great. The danger that various independent AJAX implementations will emerge and require developers to code to 2 different implementations is also pretty big. Anyone remembers the Netscape-vs-IE wars?
The asynchronous nature of AJAX may pose some problems. Some ramp-up time is required for developing at ease in an asynchronous environment if you have not had to deal with asynchronous applications.
My opinion is that currently AJAX is pretty good for small tasks pertaining to presentation. Let’s say you have a result set presented in a list and you want to display detailed information about an object in that list without refreshing the page. You could do it in AJAX. You could share various presentation objects across a site with AJAX as well.
What you should probably not be doing right now is embark on large-scale projects revolving around this immature technology.

