2

If XMLHttpRequest is used with asynchronous mode, then are the onreadystatechange callbacks for 0,1,2 states called in UI thread only or in the background thread?

And is it possible that this behaviour could be different in different browsers?

Best Regards, Keshav

1 Answer 1

1

Unless you're specifically using background workers (which are browser extensions and not universally implemented yet; i.e. you'd know if you were using them), everything will always run in the same thread. That's how JavaScript works.

Of course, some implementations might optimize things by running JS in a separate thread, but this will always be invisible to you.

Sign up to request clarification or add additional context in comments.

4 Comments

do you mean even if i am using xmlhttprequest in async mode the browser does not use the native threading support for the callbacks?
@keshav.veerapaneni: What the browser does it up to the browser. From your (the user's) perspective, everything runs in a single thread.
thanks for the quick response, so it means if the browser uses single thread for these operations then running a long running background operation in ready state 4 will hang the browser for such browser implementations
@keshav: Yes, it will hang. If you want to see the single-threadedness, try running an infinite loop in a click event handler and watch your page freeze.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.