tags:

views:

249

answers:

3
+1  Q: 

GWT Lazy Loading

I want to develop a GWT application. The application contains 8 modules and all the modules run in a single page.

I have links for all the 7 options on the top.

When the page loads I want only the home content to be loaded and displayed.

Only when the user clicks the menu options, the menu content should load.

Can anyone suggest the best way to achieve this.

A: 

AFAIK, lazily loaded (or pluggable) modules can't be done in GWT. Partly this is due to the way the GWT compiler works - it likes to import all the code that it is ever going to see and then optimises and prunes it as viciously as possible (to make the resulting JS files as small and lead as possible). If it doesn't have access to all the source code up front, it might make optimisations that will break the pluggable modules (especially since nothing in the "core" application may reference the classes that the lazily-loaded modules need to work properly - the GWT compiler would prune those "unused" classes in the core module).

This stackoverflow question from May 09 asks the same thing and has the same answer - it can't be done.

I searched high and low about six months ago for an answer to this problem, because I really wanted to do what I believe you're asking for. Never found a solution.

(I haven't used GWT 2.0 - it might have addressed the issue)

Ash
GWT to has addressed this issue.
Carnell
+5  A: 

This has been addressed in GWT 2.0... First you'll remove the separate entry points you have for each module - since they're all on the same page, you only need one entry point per page.

Then you can use the GWT.runAsync() method at each point that you feel can be a split... it automatically cuts up the code into chunks that are downloaded as and when necessary.

Look here for the docs.

Sudhir Jonathan
What about on the compile side though? Do you still have to compile everything any time you want to make a change to a "plugin" module? The code-splitting guide didn't seem to be particularly clear on this.
Ash
GWT 2.0 also comes with a very interesting dev mode that removes that headache (or completely hides it, anyway). You run the app, install a browser plugin, and make changes and hit refresh. Thats it - http://code.google.com/webtoolkit/doc/latest/ReleaseNotes.html#NewFeaturesDevMode
Sudhir Jonathan
A: 

Thank you for your answer. You are right that the whole Javascript code gets downloaded.

But there must be a way like say on of module is View Profile. Only when the user clicks the view Profile link, the widgets related to displaying my profile needs to be created. is this not possible.

Ramkumar
Its quite easily possible... I've attached the link to the docs on top. There are also a lot of Google I/O talks on this topic
Sudhir Jonathan