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) {
if (id.equals("1")) {
GWT.runAsync(new RunAsyncCallback() {
@Override
public void onFailure(Throwable reason) {}
@Override
public void onSuccess() {
img.setResource(MyImages.INSTANCE.img1());
}
});
}
}
if (id.equals("2")) {
GWT.runAsync(new RunAsyncCallback() {
@Override
public void onFailure(Throwable reason) {}
@Override
public void onSuccess() {
img.setResource(MyImages.INSTANCE.img2());
}
});
}
}
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
source
share