Start GWT App from JavaScript

72 views
Skip to first unread message

Daniel

unread,
Dec 17, 2011, 1:18:06 PM12/17/11
to google-we...@googlegroups.com
Hi,
I want to embed a GWT App into another non-GWT website. Probably about 90% of the time the GWT App won't be needed by the user. So I don't want to include the nocache.js file when the page first loads. I'd rather include it via JavaScript when the user needs some GWT features. I tried document.write() to include the nocache.js file but it doesn't work (I only get a blank page). Is there a way to start the GWT app from JavaScript?

As a workaround I already looked at GWT's runAsync() to reduce the size of the of the code which get's loaded before onModuleLoad(). But that's not really a good option for me since the GWT project has many dependencies to other frameworks which will all get loaded before the first onModuleLoad() nevertheless.

Any suggestions?
Thanks

Ed

unread,
Dec 17, 2011, 1:40:34 PM12/17/11
to google-we...@googlegroups.com
Have a look at gwt-exporter: http://code.google.com/p/gwt-exporter/
- Ed

Daniel

unread,
Dec 17, 2011, 1:51:02 PM12/17/11
to google-we...@googlegroups.com
Thanks.
But I assume before I can call the exported functions from JavaScript I still have to include the GWT App (i.e. nocache.js) into the webpage? Or how else would JavaScript know of these functions? So this brings me back to the original problem how to start the GWT app from JavaScript.

Ed Bras

unread,
Dec 17, 2011, 2:10:49 PM12/17/11
to google-we...@googlegroups.com
Read the manual/examples of gwt-exporter!

On Sat, Dec 17, 2011 at 2:51 PM, Daniel <eklip...@googlemail.com> wrote:
Thanks.
But I assume before I can call the exported functions from JavaScript I still have to include the GWT App (i.e. nocache.js) into the webpage? Or how else would JavaScript know of these functions? So this brings me back to the original problem how to start the GWT app from JavaScript.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/3SeST-oYepQJ.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Daniel

unread,
Dec 17, 2011, 2:38:33 PM12/17/11
to google-we...@googlegroups.com
I did read it. But according to their simple demo I still have to include the generated .js file directly into the html page:  http://code.google.com/p/gwt-exporter/source/browse/trunk/samples/src/main/java/simpledemo/public/SimpleDemo.html 
So how could I use gwt-exporter to start the GWT app from JavaScript? Because as soon as I have to include the nocache.js file all the code gets loaded directly when the page loads and not when I actually start the app.
Thanks for your time

Ed Bras

unread,
Dec 17, 2011, 2:41:57 PM12/17/11
to google-we...@googlegroups.com
Not of you use code splitting I assume.
And you can also delay the loading of the js file and not directly included in your html page (just like google api's are loaded). Just load your js file yourself in your js file.. (just what code splitting does)
- Ed

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.

Daniel

unread,
Dec 17, 2011, 2:55:49 PM12/17/11
to google-we...@googlegroups.com
How can I "delay the loading of the js file and not directly included in your html page" ? That's exactly the question here;) Seems to me I have to include the first nocache.js file on the host page and can NOT include this dynamically from JavaScript? Code splitting and runAsync() isn't really a solution for me because all the code of the frameworks still gets loaded with the first part of the code (see my first post).

After searching for a few hours I've found that writing an own GWT linker (i.e. implementing com.google.gwt.core.ext.linker.AbstractLinker) might be a possible solution to my problem. Can anyone confirm this? Since I have no idea how to write my own linker or even get startet it would be comforting to know that if I start following this path it will definietly lead to a solution.. ;)

Ed Bras

unread,
Dec 17, 2011, 3:02:12 PM12/17/11
to google-we...@googlegroups.com
With gwt-exporter you create the desired js. 
This can be loaded in your own js.
How? -> First google result (10ms):

- Ed

On Sat, Dec 17, 2011 at 3:55 PM, Daniel <eklip...@googlemail.com> wrote:
How can I "delay the loading of the js file and not directly included in your html page" ? That's exactly the question here;) Seems to me I have to include the first nocache.js file on the host page and can NOT include this dynamically from JavaScript? Code splitting and runAsync() isn't really a solution for me because all the code of the frameworks still gets loaded with the first part of the code (see my first post).

After searching for a few hours I've found that writing an own GWT linker (i.e. implementing com.google.gwt.core.ext.linker.AbstractLinker) might be a possible solution to my problem. Can anyone confirm this? Since I have no idea how to write my own linker or even get startet it would be comforting to know that if I start following this path it will definietly lead to a solution.. ;)

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.

Daniel

unread,
Dec 17, 2011, 3:33:46 PM12/17/11
to google-we...@googlegroups.com
The nocache.js file from gwt-exporter also can't be loaded dynamically (not with document.write() and not with the function from your link above).

Seems to me writing a linker is the only solution?

Derek

unread,
Dec 18, 2011, 5:39:16 PM12/18/11
to Google Web Toolkit
I don't think you need to write a linker. Just create a script element
in your js code and add it to the DOM when you need it.

For example,

<button onclick="dogwt()">Do GWT</button>

function dogwt() {
var s = document.createElement("script");
s.src = "my.nocache.js"
document.body.appendChild(s)
}

This way is the same way jsonp works, so Google jsonp if my code is
broken or you need more options. (Forgive me for not testing that
code, posting from a tablet.)

document.write() clears the entire document before writing, which is
why your screen goes white.

Derek

Reply all
Reply to author
Forward
0 new messages