Friday, November 9, 2012

Re: Placement of boot script in body vs. head

Hi Thomas,

> <body>
> <noscript>
> You must have JavaScript enabled blah blah blah
> </noscript>
> <script>
> document.write("<div id='loading'>Loading…<" + "/div>");
> </script>
> <script src="myapp/myapp.nocache.js"></script>
>
> With the first thing you do in the onModuleLoad is
> Document.get().getElementById('loading').removeFromParent();
>
> The "bootstrap script" is "as early as possible within the body" yet not at
> the very beginning.

Okay, so body placement is required in this case. OTOH if we don't
write to the document before the boot script, then I guess there's no
reason to avoid placing it in the head if that works (as it seems to),
despite what the guide recommends.

Michael


Thomas Broyer said:
>
> On Thursday, November 8, 2012 3:50:47 AM UTC+1, Michael Allan wrote:
> >
> > Hi Matthew,
> >
> > > My understanding is that when the browser sees a <script> tag, it
> > > needs to block until the script resource is available before it can
> > > resume parsing and displaying the rest of the page's contents.
> > > Putting the <script> tag at the end helps avoid this so the page
> > > renders faster.
> >
> > I was thinking along the same lines at first. But then the guide
> > says, "You want to put the GWT selection script as early as possible
> > within the body, so that it begins fetching the compiled script before
> > other scripts (because it won't block any other script requests)."
> >
> > https://developers.google.com/web-toolkit/doc/latest/DevGuideOrganizingProjects#DevGuideBootstrap
> >
> >
> It really depends on your use case and the user experience you want to have
> during loading.
> For instance, a very easy way to have a "Loading..." text on the page:
>
> <body>
> <noscript>
> You must have JavaScript enabled blah blah blah
> </noscript>
> <script>
> document.write("<div id='loading'>Loading…<" + "/div>");
> </script>
> <script src="myapp/myapp.nocache.js"></script>
>
> With the first thing you do in the onModuleLoad is
> Document.get().getElementById('loading').removeFromParent();
>
> The "bootstrap script" is "as early as possible within the body" yet not at
> the very beginning.
>
>
> > > Now that HTML has the async script
> > > attribute<
> > http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.html#attr-script-async>,
> >
> > > that would be another option if you want to keep your script tags in
> > > the header. (Note that there's a semantics difference since scripts
> > > might execute out of order depending on caching and network speeds.)
> >
>
> Also, it might only work with the xsiframe linker, as the others use
> document.write() which IIRC could destroy the document when run async.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate