Spring [br /] - Robust Ajax Architecture

Rob Gonda gave an interesting session on ajax architectures.

Best practices for architecting your ajax apps. Ajax is supposed to reduce server load, but if you are not careful, you could easily increase the server load exponentially (e.g. an out-of-control autocomplete widget). Flex/Flash are better suited for larger RIA applications.

JSON (JavaScript Object Notation) is becoming very popular lately. It is native to javascript, making it very fast on the client side because it doesn't need to be parsed like xml needs to be. Two open course projects that help integrate JSON and ColdFusion: cfjson (http://www.epiphantastic.com/cfjson/) and another one that one that I didn't catch.

Use javascript libraries and frameworks. Frameworks allow you to code for the library and not for a specific browser. There are many to choose from, each with pros and cons. Rob regularly uses and is a big proponent of jquery.

Flash plays friendly with Ajax. Rob uses Flash for XML Sockets messaging services--ColdFusion Enterprise gateway. Adobe Ajax Data Services (ADJ)--Ajax interface to Flex Data Services.

Potential Problems: back button, url history/bookmarking, search engine indexing, client side business logic, viewable source code, etc.

Architectures: return data, return html, return javascript. Don't code your business logic in javascript. Return javascript from your ColdFusion app which then gets eval()-ed in your app. Good separation of logic (MVC). Use innerHTML() to modify content and eval() for logic (only on the client, never on the server). For example, your server would send a string like this: "$('mydiv').innerHTML='some new text';", which then gets executed on the client side with a simple listener that simply evaluates the returned string with a javascript eval() call. Business logic and data should stay on the server, but it can really be up to you whether some of the UI logic exists on the client or server. Your AJAX should only be in the View of MVC.

Degradable sites--very important. Easiest way is to use hrefs + onclicks (very easy to do using an unobtrusive framework like jquery).

Switzer shows jquery coolness

Dan Switzer of qforms fame presented a ton of information about using jquery. I've been using jquery for a couple months, but he has really taken jquery to the max. He enlightened me about two jquery plugins, forms and validation, that make client-side validation easy and very powerful. We have used qforms for years, but Dan hasn't really updated it (at least publicly) in a long time. He mentioned this morning that he uses qforms "sometimes". From his presentation, it seems that he is high-on-the-hog with jquery. You can download his presentation and all his demo code from his blog.

Along with this, he mentioned several best practices in coding, such as always doing server-side validation, assuming javascript is turned off, and using unobtrusive javascript to enhance the user's experience. Check out his presentation!

BlogCFC was created by Raymond Camden. This blog is running version 5.8.