Rails and Django - AJAX (part 10/15)
AJAX
To quote the "Agile " book, AJAX "once stood for Asynchronous JavaScript and XML but now just means Making Browsers Suck Less." In general, AJAX refers to updating parts of the page without having the refresh the whole page. And thus it makes browser apps feel more like desktop ones.
Rails and Django have very different philosophies about the roles of a framework with regard to AJAX.
There are dozens of AJAX toolkits (libraries) available, both commercial and open source. One of the most important functions of these is to handle the idiosyncratic differences between browsers, as each browser implements and supports JavaScript differently. In addition, toolkits provide useful and fun things that you can add to your pages, like drag and drop, visual effects, etc.
Rails
Rails has fully embraced AJAX. And, in fact, it has standardized on a specific toolkits (prototype and Scrip.aculo.us ) and encapsulated them so you can add AJAX effects to your pages using the Ruby and Rails code, without every having to touch JavaScript.
This is accomplished through a different "partial" template file format called .rjs. When you include an rjs template, it injects the appropriate JavaScript code into your page. You pass it variables, for example, that are passed to the Scriptaculous libraries. This is considered "server-side JavaScript" because you are programing your web app, as usual, on the server side. Although the JS does run on the user's browser, you're not necessarily thinking about that.
Django
AJAX has been hotly debated among the Django developers but their direction seems clear. Django does not intend to select or standardize on any particular toolkit. Instead, they will provide a library in the framework for "serializing" objects so they can be passed between your Django app on the server and JavaScript in the user's browser. There are standards for this, such as JSON - JavaScript Object Notation, which will be supported.
In this way, you are free to choose any AJAX toolkit you want, and integrate it with your Django application. (For example, the Dojo toolkit is well regarded).
The Django developers have publicly stated that like HTML and CSS, they regard Javascript a basic technology that should be mastered by any web developer. After all you don't ask the framework to write your stylesheets, do you? There are blog tutorials out there showing how easy it is to do AJAX with Django.
Opinion
While I understand the attitude of Django about AJAX, its not what I want right now. It may be what I need at some point down the road, but if I can get 90% of what I need wrapped up in a nice little package without having to program in Javascript, I'll take it. Then if I outgrow that wrapper, so be it, I'll research other toolkits, learn to use JSON, and so on.
Thus, I really appreciate what the Rails team has done with AJAX. Anything to get me quicker to my goal of a well-oiled, quality web site, the better. The fact they've established a strong foundation with the rjs template idea, all the better.
Django's serialization is under development.
Conclusion: I rate Rails a 4 and Django a 3 (I'm being generous to Django taking on faith that it's not so hard to roll your own AJAX with what they provide).
| AJAX | Rails | Django |
| Support for AJAX | integrated Scriptaculous; rjs templates | object serialization |
| MY RATING: (1=worst, 5=best) | 4 | 3 |
There are no comments attached to this item.



