Ajax threading

The interesting thing about Ajax and JavaScript is that browsers run JavaScript in a single thread. Actually even same thread is often used for both JavaScript execution and UI event handling. So how is it possible to support asynchronous requests?

It turns out that when new asynchronous request is made UI thread spawns worker thread that handles sending the request to server in background. This thread is completely hidden from developers and only notifies UI thread when response has been received from server. So it is possible to make multiple asynchronous calls in a row before receiving any response but only one callback in JavaScript will be executed at a time.

Some other interesting posts on this subject: http://www.alexyoung.org/articles/show/16/dismantling_browser_ajax_handling http://www.javascriptkata.com/2007/06/04/ajax-and-javascript-dont-use-threads/

Please comment if you have additional experience on this.

Labels

ajax ajax Delete
threading threading Delete
javascript javascript Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.