GWT Code Split Template for ClientBundle Image Resources

In my large GWT project, I have a ClientBundle for my image resources. I defined about 40 GIF files inside it. (each file is about 5 KB)

Then I create a class with a static method to set the correct image on obj, which receives as parameters:

 public static void setImageFromId (String id,final Image img) {

    //for 1.gif
    if (id.equals("1")) {
        GWT.runAsync(new RunAsyncCallback() {
            @Override
            public void onFailure(Throwable reason) {}
            @Override
            public void onSuccess() {
                img.setResource(MyImages.INSTANCE.img1()); //MyImages is the ClientBundle
            }
        });
    }             

 }

    //for 2.gif
    if (id.equals("2")) {
        GWT.runAsync(new RunAsyncCallback() {
            @Override
            public void onFailure(Throwable reason) {}
            @Override
            public void onSuccess() {
                img.setResource(MyImages.INSTANCE.img2()); //MyImages is the ClientBundle
            }
        });
    }             

   //etc. for other images 3, 4, 5, ...
   //...

 }

I want to know if this is a good template for breaking code? because if I do not, all 40 files will be cached in the client browser on the first call, but this is not necessary.

RESPECT

+5
source share
1 answer

, . , , .

, , - , , , , .

:

if (id.equals("1")) {
  img.setSrc(MyImages.INSTANCE.img1().getUrl());
} else if (id.equals("2")) {
  //.. and so on.
}

, . Firebug Chrome, , .

, , , , .

+1

All Articles