Hi Dave,

Since you mentioned the Maps API by name, I have just introduced a
library in the gwt-google-apis project that can load the Maps API on
demand, instead of in the host page.  The module is
com.google.gwt.ajaxloader.AjaxLoader and is checked into the SVN
repository on the project code site at
http://code.google.com/p/gwt-google-apis.

The code you gave for injecting a script element is correct, but the
catch is that you have to wait for the script to load before you try
to use any of the functions in that API.  After you inject the script
element into the DOM, you regain control immediately and the script
downloads in the background.

With the Google Ajax Loader, there is a callback parameter you can
specify on the query line - you create a callback method to execute
your maps code (say, named 'myCallbacFunc'), then you load the loader
script named 'http://www.google.com/jsapi?callback=myCallbackFunc' ,
wait for the  callback function.  Inside of myCallbackFunc(), you need
to then use the google.load() method defined by the AjaxLoader API to
load the actual Maps API.

Hopefully the other APIs you are using also provide a callback.
Otherwise, you could do some hack like periodically checked for api
methods to be defined in a timer callback (yuck!) to see if the API is
now ready to be called.

-Eric.

On Thu, Feb 19, 2009 at 12:30 AM, Dave Schweisguth <[email protected]> wrote:
>
> I'm working with a consumer web app which uses GWT extensively and
> also integrates several third-party services (ads, user tracking,
> etc.) via script tags. (For context, we generate as much of our HTML
> as possible, including those script tags, on the server side, and add
> behavior with GWT. This keeps us search-engine friendly and reduces
> the time to when the user begins to see interesting content.)
> Unfortunately, all those third-party scripts run before GWT does,
> since all of the scripts are in the page and run during page load,
> while GWT runs on DOMContentLoaded. The result is that some prominent
> page elements aren't drawn, and behavior isn't available, until all of
> the third-party stuff is finished, which takes much too long (a couple
> of seconds).
>
> We'd rather have a happy user using the page right away and let the
> ads and user tracking and such complete afterwards, so we'd like all
> of the third-party stuff to run after GWT does. It seems as though the
> right way would be to write the third-party script tags into the DOM
> in our GWT code, after we've done all of the real application stuff
> that we want to do first. My first crack at this was (warning, from
> memory):
>
> ScriptElement script = ScriptElement.as(DOM.createElement("script"));
> script.setSrc("http:///third-party-service.com?...";);
> script.setType("text/javascript");
> Element container = DOM.getElementById("anId");
> container.appendChild(script);
>
> The above is at the end of my onModuleLoad. I also tried
> DeferredCommand.add(new Command() {  // the same code }). Either way
> the result is the same:
>
> - in the hosted mode browser and IE 7, nothing happens (and there is
> no error in the hosted mode browser)
> - in Firefox 3,
>  - the page loads until GWT gets around to running the above code
>  - the script tag issues a request to the correct URL
>  - the whole page is replaced by the content at that URL
>  - Firebug reports an error in Google Maps code, which is running
> from our app, not from the third-party tag
>  - the browser hangs!
>
> Can anyone either explain what's going on and suggest how to fix it,
> or suggest another way to accomplish the goal?
>
> Thanks!
>
> >
>



-- 
Eric Z. Ayers - GWT Team - Atlanta, GA USA
http://code.google.com/webtoolkit/

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

Reply via email to