0

Possible Duplicate:
JavaScript multithreading

When I open a web page in browser, how many threads are started to render the DOM and execute the Javascript code?

Is it possible to execute Javascript functions with multi-threads?

1

6 Answers 6

3

You can make the use of webworkers in modern browsers

http://www.html5rocks.com/en/tutorials/workers/basics/

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

Comments

0

The short answer is no, you cannot run multithreaded code in javascript.

The longer answer is that you can simulate it. This question on SO might be helpful: Multithreaded JavaScript how to?

2 Comments

... unless you use web workers in a modern browser.
I know, I was in the process of adding that to my answer :)
0

Javascript code runs in a single thread . You can not start seperate thread but you still can use asynchronous functions to achieve that like setTimeOut and setInterval .

Comments

0

In general there is only one UI thread, but you can run JS in parallel with WebWorkers in HTML5.

Comments

0

You can use WebWorkers for threads, but it cant work with dom. Also you may try simulate it by setInterval

1 Comment

The script calling the webworker can work with DOM!!!
0

Another idea that people use at times is to make use of iframes. If your application can be modeled as set of iframes(like facebook), you can leverage this. Google chrome is highly optimized for this. Javascript in each frame executes in a separate execution context and hence can be parallelized.

2 Comments

What about other browsers, like IE, firefox, safari? Do thye provide the optimization for iframes?
Yup.. Every browser runs javascript in each iframe in a separate execution context and hence in parallel. This is a very popular technique. The downside is that the browser has to make multiple HTTP requests, x for each frame. Go through this more some more optimizatios that the iframes provide: aaronpeters.nl/blog/iframe-loading-techniques-performance

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.