1

I am using GWT in my application. For caching pictures i use ClientBundle with ImageResource. I have many ClientBundles like this:

public interface MenuBundle extends ClientBundle { 

  @Source(background.png) 
  ImageResource background();

  @Source(image_bg.png) 
  ImageResource image_bg();

...

}

and hundreds ClientBundles with same methods like this:

    public interface House1 extends House, ClientBundle { 

      @Source(house1/pic1.png) 
      ImageResource pic1();

      @Source(house1/pic2.png) 
      ImageResource pic2();

      @Source(house1/pic3.png) 
      ImageResource pic3();

    ...

    }

    public interface House2 extends House, ClientBundle{ 

      @Source(house2/pic1.png) 
      ImageResource pic1();

      @Source(house2/pic2.png) 
      ImageResource pic2();

      @Source(house2/pic3.png) 
      ImageResource pic3();

    ...

    }

   public interface House { 

      ImageResource pic1();

      ImageResource pic2();    

      ImageResource pic3();

    ...

    }

In result i have hundreds pictures on server like "*.cache.png". For fast loading i need less pictures. For this purpose i found decision:

public class ClientBundleModule extends AbstractGinModule {

 @Override
 protected void configure() {
  bind(MenuBundle.class).to(ClientBundlePack1.class);
  bind(NatureFuture.class).to(ClientBundlePack1.class);
  ...
  bind(House1.class).to(ClientBundlePack2.class);
  bind(House2.class).to(ClientBundlePack2.class);
  bind(House3.class).to(ClientBundlePack2.class);
  ...
 }
}

public interface ClientBundlePack1 extends MenuBundle, NatureFuture, ... {
}

public interface ClientBundlePack2 extends House1, House2, House3, ... {
}

Also there is Ginjector, ... But problem is :

MenuBundle, NatureFuture and other classes in ClientBundlePack1 compile in one big picture (it's good), but House1, House2, House3 and other Houses do not compile in one big picture (it's bad).

Houses compile each class House in one picture. I see problem in java way to extends implementation, to use just one same method like pic1 instead use all methods pic1.

But i need to join all Houses in one picture. There is setting, annotation for GIN to do that. Or may be is there other way for join all Houses? But i cannot rewrite code of Houses, it will break architecture of my application. I need all houses immediately after preloading, without "Lazy loading".

Thanks.

B.ARS
  • 11
  • 1
  • You know that only IE6-7 (and IE8 when using HTTPS) will use those images, right? All other browsers will have the images inlined as `data:` URLS right within the generated JS code. So is it really worth the hassle now that IE6-7 [_really_ is dead](http://gs.statcounter.com/#browser_version-CN-monthly-201109-201302)? – Thomas Broyer Mar 28 '13 at 09:50
  • I think there is one caveat to @ThomasBroyer's comment: If the image is larger than a certain threshold, then they are left in external files, otherwise they would bloat the compiled JS too much. In that case, joining the bundles together will enable gwt to sprite the images into larger files. One idea I've never tried that could be worth it: Make a BundleBundle that has `House1 house1()`, `House2 house2()` methods - apparently it is supported, and might let you squish all into one file. – Colin Alworth Mar 29 '13 at 16:40
  • The end of my last comment is mistaken - while you *can* create nested bundles, it *does not* create one giant bundle. It probably could though, but we'd need to wrestle through the implications of merging bundles that should not reference each other. – Colin Alworth Mar 29 '13 at 17:39
  • @ColinAlworth if an image is too big to be inlined, won't it also be too big to be "bundled"? (IIRC, one threshold is about the weight and another about the dimensions, but it's likely that intersection is quite large) – Thomas Broyer Mar 29 '13 at 19:38
  • I'd say no, it can still be sprite'd - 10 100x100 images would be big, but it is better to do 1 big request rather than 10 small ones. There is probably another threshold, somewhere north of 1MB where no new images should be appended though. – Colin Alworth Mar 29 '13 at 20:02

0 Answers0