[cosmo-dev] Putting the A back in Ajax
Matthew Eernisse
mde at osafoundation.org
Wed Nov 14 10:44:59 PST 2007
Howdy, Cosmo peeps.
Travis Vachon wrote:
> As you can see, we're using synchronous calls quite a bit. This means
> that while the browser is waiting for the server to return data the
> entire program hangs, something you probably noticed if you signed into
> hub yesterday. The solution is to convert all these pieces of code to a
> callback based model and make the XHR calls asynchronously.
+1 to this idea in general, with a few caveats:
1. There are some cases where sync is really what we want.
An example is grabbing the imagegrid.json file in imagegrid.js. We use
the data in that file to draw the icons in the UI, so the UI wouldn't be
at all usable without the content in that file. Maybe we can think of a
better way to get that data passed to script?
2. We would need to build in our own timeout mechanism in the UI code to
deal with the requests that never return any data.
IIRC, a lot of the sync calls are associated with the initial load of
the app.
With all-async calls and an unresponsive server, you'd get your UI, but
none of your data would be there. We'd still need to return some kind of
error to the user (but at least the error would be nicer than a script
timeout).
We need to do some work on this anyway now that we have the concept of
deleting a collection, which implies that the UI should eventually
display properly even if there's no data.
The difference would be that with a failed background fetch of their
data, eventually we need to show them the "oh noes" message.
3. Ops that users expect to happen more-or-less in real time.
This is very similar to 2. Examples would be things like renaming a
collection or updating your preferences. We can move to a callback-style
for those that are implemented as sync -- but the operation from the UI
standpoint should still pretty much block (i.e., the user sees a
processing status message until the request either succeeds or fails).
Again, the difference here is what type of error message they get. It
should still error out, but it wouldn't be an ugly script timeout.
All-in-all an excellent idea, Travis.
Matthew
More information about the cosmo-dev
mailing list