Where to store config parameters in GWT?

To do this you have a following options:

  1. Store data in client side code. GWT compiles down to the javascript and the simplest way to do this is to create a Configuration class with hardcoded values.
  2. Store data in a browser. You can use cookies or HTML5 local storage
  3. Store data on a server side and retrieve them using remote RPC.

I would recommend you go with third option.


You will probably be very happy using the Dictionary and Cookie classes in GWT.

In your html hosting file, you maintain some javascript objects declared as var.

At module load, call Dictionary class to grab the javascript objects that you have defined to store your config data.

In this way, you could have a server side managed user- or context- sensitive configuration, because occasionally I use JSP to generate the hosting file. I could manage user configuration as server side cookies stored in a database.

So ... today is Thursday ... the user has a history of visiting Manchester Utd FC web site every Thur, etc, let me give the user a different config based on context/user-sensitive algorithm. And on Monday mornings, the user config would include ad data for 10 hour energy beverages.

In this way, your gwt client would not have to request context-sensitive config data from the server.

But then of course, this is no way to store authentication/security data like passwords. I don't think you should even consider storing authentication/security data in client-side code. Even after javascript obfuscation, storing such data this way is an open invitation to persistence of malicious intent. Such data, if client-side storage is desired, would be best served by client-side cookies, using the GWT class Cookies.