tags:

views:

2894

answers:

2

In order to provide nice URLs between parts of our app we split everything up into several modules which are compiled independently. For example, there is a "manager" portion and an "editor" portion. The editor launches in a new window. By doing this we can link to the editor directly:

/com.example.EditorApp?id=1

The EditorApp module just gets the value for id and loads up the document.

The problem with this is ALL of the code which is common between the two modules is duplicated in the output. This includes any static content (graphics), stylesheets, etc.

And another problem is the compile time to generate JavaScript is nearly double because we have some complex code shared between both modules which has to be processed twice.

Has anyone dealt with this? I'm considering scrapping the separate modules and merging it all back into one compile target. The only drawback is the URLs between our "apps" become something like:

/com.example.MainApp?mode=editor&id=1

Every window loads the main module, checks the value of the mode parameter, and and calls the the appropriate module init code.

+3  A: 

I have built a few very large applications in GWT, and I find it best to split things up into modules, and move the common code into it's own area, like you've done. The reason in our case was simple, we had some parts of our application that were very different to the rest, so it made sense from a compile size point of view. Our application compiled down to 300kb for the main section, and about 25-40kb for other sections. Had we just put them all in one the user would have been left with a 600kb download, which for us was not acceptable.

It also makes more sense from a design and re-usability point of view to seperate things out as much as possible, as we have since re-used a lot of modules that we built on this project.

Compile time is not something you should generally worry about, because you can actually make it faster if you have seperate modules. We use ant to build our project, and we set it to only compile the GWT that has changed, and during development to only build for one browser, typical compile times on our project are 20 seconds, and we have a lot of code. You can see and example of this here.

One other minor thing: I assume you know that you don't have to use the default GWT paths that it generates? So instead of com.MyPackage.Package you could just put it into a folder with a nice name like 'ui' or something. Once compiled GWT doesn't care where you put it, and is not sensitive to path changes, because it all runs from the same directory.

rustyshelf
A: 

Ok. I really get the sense there really is no "right" answer because projects vary so much. It's very much dependent on the nature of the application.

Our main build is composed of a number of in-house modules and 3rd party modules. They are all managed in seperate projects. That makes sense since they are used in different places.

But having more than one module in a single project designed to operate as one complete application seems to have overcomplicated things. The original reason for the two modules was to keep the URL simple when opening different screens in a new window. Even though had multiple build targets they all use a very large common subset of code (including a custom XML/POJO marshalling library).

About size... for us, one module was 280KB and the other was just over 300KB.

I just got finished merging everything back into one single module. The new combined module is around 380KB. So it's actually a bit less to download since most everyone would use both screens.

Also remember there is perfect caching, so that 380KB should only ever downloaded once, unless the app is changed.

Mark Renouf
our app runs as HTTPS, so there is no caching over multiple visits, so the size was really important to us. I think the right answer in most cases is to split them up, for maintainability, management, and compile speed
rustyshelf