Domi
Domi

Reputation: 1389

gwt code splitting with an existing Project

I have a project with a mobile and Desktop view, with over 100 classes, my question is now : What the best way is to splitt up this code ?

looking in the complier report which class is over 10kB and call it via a runAsync?

Upvotes: 1

Views: 89

Answers (1)

Andrei Volgin
Andrei Volgin

Reputation: 41089

Typically, you split your application into logical pieces based on a user behavior, not a code structure. For example, if all users enter View A, and then only some of them go to View B and very rarely users go to View C (e.g. "Settings" view), then View B is a good candidate and View C is an obvious candidate for splitting.

When you split your code, there are two key fragments in addition to each split point: the initial fragment and the leftover fragment. The compiler decides which class goes where based on your split points. If a class is called from many different places, it will end up either in the initial fragment or the leftover fragment, which means it will always be loaded when a user accesses your app. Only classes which are specific to a split fragment will be loaded when needed.

The best way forward is to create a split point in a place that looks the most promising, compile the app, and then examine the compile report to see how your code size broke down between the initial fragment, the split fragment, and the leftover fragment. It will give you a good idea if splitting is worth it for your app.

Upvotes: 3

Related Questions