jgleoj23
jgleoj23

Reputation: 262

How to avoid downloading the same js files, images, css etcetera in GWT

I'm making a GWT app with multiple modules. My app has plugins(extensions) which means that I have to get the modules at runtime and third party developers need to upload their plugins at runtime. go here for more context. I don't know what modules I'll get until runtime. As far as I know you can't inherit a new module at runtime outside of telling the server to change the gwt.xml file to inherit the right module and recompiling at runtime which would be unacceptably slow. GWT warned against this and rightly so. I've had a lot of issues. One of which is that the modules all share some code and I'm afraid that each plugin will get that code. This would be very inefficient. How can I make this more efficient? Is there a better way to get plugins?

Upvotes: 0

Views: 58

Answers (1)

Andrei Volgin
Andrei Volgin

Reputation: 41089

This is what Code Splitting is for.

You can split each of your optional modules into a code fragment and let the compiler do its magic. The compiler will see which code fragments share the same code, and it may decide that it's more efficient to merge these fragments into a single fragment rather than keep them separate. Or it may move some code into a fragment that loads last - after the initial fragment and the ones your users need immediately.

In my experience, it's hard to improve significantly by hand compared to what a compiler would do for you automatically. The only optimization that I would suggest is playing around with the maximum number of fragments (i.e. telling the compiler how aggressive it should be in merging similar fragments) - the results would be slightly different and you can choose the best option based on your expected app usage patterns.

Upvotes: 1

Related Questions