gwtclientbundle

How does GWT ClientBundle caching work?


I am trying to better understand the use of GWT ClientBundle and caching.

If I have a large text file, for example, that I'd like to make available to my client, I can use

public interface MyResources extends ClientBundle {
    public static final MyResources INSTANCE =  GWT.create(MyResources.class);    
      @Source("myText.txt")
      public TextResource myText();
}
//-- then later to use the text
String text = MyResources.INSTANCE.myText().getText(); 

Does this mean that the file "myText.txt" would be downloaded from the server the first time the client runs the app, and then the file would be stored in the browser's cache so that in future uses of the app, the file does not need to be downloaded?

If so, what happens if I change "myText.txt", does the app know to get the new version?

Finally, if the file is indeed stored in the cache, how then is this different from local storage in HTML5?

Thanks.


Solution

  • What's common for both cases is, that the results will be in *.cache.* files, with unique names that change automatically whenever the contents of a source file change (you'll have to recompile the GWT app though!)

    This allows the server to deliver these files with appropriate caching HTTP headers (you'll have to set this up yourself!) For the client this means, that it will not only be able to cache the contents (which it does anyway, even if those headers aren't set), but it can even skip asking the server, if a newer version exists.

    The big advantage of ClientBundles is, that the file names will change automatically. The biggest disadvantage is, that you must recompile your GWT app, when a resource changes. If you don't want that, then it's better to use some other approach to load the files: You can still make the browser cache any file you like (by setting the HTTP headers), but then you'll have to be careful to manually give them a new name, when the content changes.