Okke's blog

Wednesday, October 26, 2005

Unobtrusive Ajax and degradability of the web

The last few days I've been thinking about unobtrusive JavaScript and Ajax and the degradability of the web. One of the arguments the anti-Ajax folks use is that users are unable to bookmark Ajax pages. I think they didn't quite get the point. For that, we first have to examine why one should use Ajax. I think Ajax is a nice add-on to websites. It's not a necessity to use Ajax, but if used properly it can help the user with faster response times and a more steady field of view. Ajax can be nicely used for things like auto-completion (for example, when you have to type in someone's email address) and when someone has a list-view with 'add item' field underneath. (E.g. a blog with comment fields. When you add a comment you immediately see what you added. You don't have to watch while the whole page is reloading and when that's done scrolling to your new-made post). However, I do not think Ajax should be used when there is anoter view to be rendered. For example, if you list users and someone clicks a user to view more information about him/her, a whole new page should be rendered with a proper url. The reason for this is that someone can still bookmark anything they would possibly want to bookmark. Another argument the anti-Ajax crew uses is that people without javascript enabled can't do a thing. This isn't always the case, though. The keyword for this problem is unobtrusive javascript. In other words: don't rely on it. Allow everything to be done through normal post-backs. Sometimes this can be quite hard, though. The example with the blogpost can be solved easily with unobtrusive javascript:
  • Create the form with normal postback parameters. Get it to work properly without javascript.
  • Then add a javascript layer. Don't use inline javascript, but you'd rather want to dynamically select the form. Disable the postback and put a javascript that handles the Ajax-calls instead.

Now everything still works for people without javascript, and it works excellent for people who enabled javascript.

Mind you, are some things that are hard to do without javascript. What about sorting a list at different ways? Or how to allow the user to move things up or down a list? There are some nifty drag-and-drop scripts circulating at the moment. Without javascript, these features are a lot harder to script into your application.

You could program al these features twice: one serverside solution and one clientside solution. When you have to deploy a site, you probably won't have time for this sort of thing. Then there is just one solution: just tell them you can't do these things if you have disabled javascript. Too bad for them, I guess. A sidenote: be sure you do enable all critical features of your application for use without javascript. Use javascript if you can, but don't depend on it.

[edit] This might be a point for RoR users. Most rails-generated Ajax code is inserted inline. Isn't that as evil as inline CSS?

[edit 27th october] This guy says another good thing about the how and why of Ajax

Any thoughts on these matters?


Post a Comment

Links to this post:

Create a Link

<< Home