tags:

views:

67

answers:

1

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: Most browsers will allow a maximum of two simultaneous connections for fetching resources.

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 ) ?

+2  A: 

From the same page:

  • <img> tags are not guaranteed to be done loading when onModuleLoad() is called.
  • <script> tags are guaranteed to be done loading when onModuleLoad() is called.

So when onModuleLoad() is executed the externalScriptOne.js is loaded, it doesn't start before all script tags are loaded.

Hilbrand
So, the OnModuleLoad wasn't fired because the parser is fetching the externalScriptOne.js . right ? thanks in advance
CHAPa
yes that is correct. it's not fired until the externalStricptOne.js is loaded. I'm not sure if this is a feature of script tags or if GWT registers itself at body.onload. But as mentioned it is guaranteed all scripts are loaded when onModuleLoad is called.
Hilbrand
Maybe the GWT register anything on Body.OnLoad Event. u are right, im looking for this in the GWT Compiled Script. But from the google´s page "<img> tags are not guaranteed to be done loading when onModuleLoad() is called." break the theory about body.onLoad event.
CHAPa