1

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

  1. copy all javascript files into the war folder (undesireable); and
  2. 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.

1 Answer 1

1

You can inject scripts in your desired order by putting them into TextResources, which can be synchronous or asynchronous.

If you want to keep these scripts outside of your main app, you can load them first, then inject them in a desired order.

Sign up to request clarification or add additional context in comments.

1 Comment

TextResource and ExternalTextResource only load files deemed safe (ie not javascript files). The solution I have found is similar to this which uses a similar implementation to ExternalTextResource with the safety validation removed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.