GWT Bootstrap Question

95 views
Skip to first unread message

Thiago Dantas

unread,
Jul 14, 2010, 10:03:28 AM7/14/10
to Google Web Toolkit
Reading the GWT Bootstrap on Googles page, i have some question.
(http://code.google.com/p/google-web-toolkit-doc-1-5/wiki/
FAQ_WhenDoModulesLoad )

Assumptions from the Google Page:
a. Most browsers will allow a maximum of two simultaneous
connections for fetching resources.
b. <img> tags are not guaranteed to be done loading when
onModuleLoad() is called.
c. <script> tags are guaranteed to be done loading when
onModuleLoad() is called.

The HTML Page:

<html>
<body onload='alert("w00t!")'>
<img src='bigImageZero.jpg'></img>
<script source='externalScriptZero.js'></script>
<img src='bigImageOne.jpg'></img>
<img src='reallyBigImageTwo.jpg'>
</img> <script src='com.example.app.App.nocache.js'></script>
<script src='externalScriptOne.js'></script>
</body>
</html>

So , the bootstrap is composed of:

1. The HTML document is fetched and parsing begins.
2. Begin fetching bigImageZero.jpg.
3. Begin fetching externalScriptZero.js.
4. bigImageZero.jpg completes (let's assume). Parsing is blocked
until externalScriptZero.js is done fetching and evaluating.
5. externalScriptZero.js completes.
6. Begin fetching bigImageOne.jpg and reallyBigImageTwo.jpg
simultaneously.
7. bigImageOne.jpg completes (let's assume again).
com.example.app.App.nocache.js begins fetching and evaluating.
8. ...nocache.js completes, and the compiled script (...cache.js)
begins fetching (this is non-blocking).
9. ...cache.js completes. onModuleLoad() is not called yet, as we're
still waiting on externalScriptOne.js to complete before the
document is considered 'ready'.
10. externalScriptOne.js completes. The document is ready, so
onModuleLoad() fires.
11. reallyBigImageTwo.jpg completes.
12. body.onload() fires, in this case showing an alert() box.

The question:

How the JAVASCRIPT knows that the document is "ready" to begin
onModuleLoad function ( step 10 ) ?
The "ready" state is reached after all scripts be loaded and
evaluated, how do that using javascript,i.e, how execute a function
after all script tags be loaded ?

Thomas Broyer

unread,
Jul 14, 2010, 7:10:58 PM7/14/10
to Google Web Toolkit


On 14 juil, 16:03, Thiago Dantas <thiagoch...@gmail.com> wrote:
> Reading the GWT Bootstrap on Googles page, i have some question.
> (http://code.google.com/p/google-web-toolkit-doc-1-5/wiki/
> FAQ_WhenDoModulesLoad )

Unless you're still using GWT 1.5, the up-to-date doc is here
http://code.google.com/webtoolkit/doc/latest/DevGuideOrganizingProjects.html#DevGuideBootstrap

>  How the JAVASCRIPT knows that the document is "ready" to begin
> onModuleLoad function ( step 10 ) ?

Depending on the browser:
- using the DOMContentLoaded event
- using a timer and checking the document.readyState value
The template is here:
http://code.google.com/p/google-web-toolkit/source/browse/trunk/dev/core/src/com/google/gwt/core/linker/IFrameTemplate.js#285

>  The "ready" state is reached after all scripts be loaded and
> evaluated, how do that using javascript,i.e, how execute a function
> after all script tags be loaded ?

Just include a <script> after another <script>, the second one is
guaranteed to be executed after the first has been downloaded (if
external) and executed (example: load a library,then use it).
But in this case, as suggested in the doc, the *browser* communicates
that the document is "ready" (DOMContentLoaded fires, or
document.readyState is either loaded or complete) only when all
scripts are loaded and executed. This is because a script can
document.write() to generate content in the document, that affects how
it is parsed! (<b><script>document.write('</b>');</script>foo closes
the <b> so foo is not bold; <script>document.write('<b>')</script>foo</
b> makes foo bold; run the same with javascript disabled and look at
how different things are)
Reply all
Reply to author
Forward
0 new messages