Synchronous versus Asynchronous
Douglas Crockford posted on the Yahoo! User Interface Blog about Synchronous v. Asynchronous, since the Asynchronous is more complex to manage, many prefer using XMLHttpRequest in Synchronous mode which could have a negative effect specially on high load or slow website link, because the JavaScript engine is blocked until the request completes. That's why today we use AJAX and not SJAX, and the complexity of asynchronous programming is better handled today with the multitude of frameworks and techniques which make AJAX interfaces more fluid.
Many people prefer to use it synchronously. When used this way, the JavaScript engine is blocked until the interaction with the server is complete. Because it blocks, the flow of control looks a lot like an ordinary function invocation. Temporal complexity is abstracted away, leaving a very familiar and comfortable programming pattern. It works particularly well when the server is on the same machine, or nearby on the LAN. Unfortunately, it can perform very badly if the server is under heavy load, or if the browser is connected to the server over a slow link. Because the JavaScript engine is blocked until the request completes, the browser will be frozen. The user cannot cancel the request, cannot click away, cannot go to another tab. This is extremely bad behavior. Fortunately, XMLHttpRequest provides an option for asynchronous operation. When you set the asyncFlag flag to true, the JavaScript engine does not block. Instead the request returns immediately, with a potential action that will be triggered later when the result on the request is known. The Yahoo! Connection Manager provides a very nice interface for this.


Subscribe to AJAX Magazine's feed