I'm looking for a way to ensure the ordering of external scripts in GWT. The way has to be compatible with SuperDevMode. The two ways I have come up with so far are
- copy all javascript files into the war folder (undesireable); and
- use ScriptInjector in onModuleLoad().
I have opted to go with option 2, however I wish to know if there is another way of executing scripts in a specific order besides cascading callbacks, as this results in a significant drop in performance. I was wondering if anyone else has run into this problem.
Below is a simple example of cascading callbacks.
ScriptInjector.fromUrl(GWT.getModuleBaseForStaticFiles() + "somescript.js").setCallback(new Callback<Void, Exception>() {
@Override
public void onFailure(Exception reason) {
}
@Override
public void onSuccess(Void result) {
// repeat ScriptInjector.fromUrl() n many times
}
}).inject();
As of now I am looking for a way to asynchronously download all javascript files in parallel (to store in a String?), then use ScriptInjector.fromString(jsBody) to inject them in the order required. Is there a way of downloading the script bodies into a specific class using GWT? Any suggestions or improvements to my approach would be greatly appreciated.
Thanks in advance.