ichaki5748
ichaki5748

Reputation: 2033

Can page rendering run simultaneously with JavaScript?

I have an overridden GWT DialogBox that has as a widget overridden PagingScrollTable. I have something like this in my code:

1) DialogBox dialog = new ...
2) dialog.center(); 
3) Window.alert("Hello"); 

In IE I would see alert after loading of table’s header but before loading of table’s content (about 1000 rows). But javascript is single-threaded language so how can it be? May it be a browser issue or issue of my code?

Thanks!

Upvotes: 1

Views: 134

Answers (2)

Spudley
Spudley

Reputation: 168853

Javascript may be single-threaded, but the browser isn't, and page rendering is not done by the Javascript engine, so there's no conflict that Javascript can be running while the page is rendering.

(in fact, you can add the async attribute on the <script> tag to tell the browser explicitly to do this, although sadly this attribute isn't fully supported in all browsers yet)

Upvotes: 1

synthesizerpatel
synthesizerpatel

Reputation: 28056

Javascript is asynchronous (and it runs inside a thread in the browser so it's not in lock-step with the page loading the way you might think it is. Once the javascript itself is loaded, it need only be triggered by an event to run, or, the fact that it's loaded is enough to run it. '' tag contents are processed by the browser instantly - so if you have code that isn't wrapped in a 'function' that you bind to 'unload' or something similar - it'll just run whenever it shows up in the DOM.

Upvotes: 0

Related Questions