Sunday, January 6, 2008

GWT Development or Production Mode

Here is a nice trick to know if your GWT application runs on hosted mode (development mode) or does it runs in production mode on a real web site.

Why do you need this? Because your access to the server side is different between development and production modes, and because you might your application behave differently between this two modes.

So to do this you would need to have two main html files one for development mode and another one for production mode, the two html are the same expect in the production mode you would put this following line:

‹iframe id="production" style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; WIDTH: 0px; BORDER-BOTTOM: 0px; HEIGHT: 0px"›‹/iframe›

and you can also put your advertisements like Google AdSense and Google analytics and other production stuff.

after you put this write this code in your main module class:

public void onModuleLoad() {
Object isProduction = RootPanel.get("production");

if (isProduction!=null) {

Also create this ClientUtil class:

public class ClientUtil {
private static boolean isProduction = false;

public static boolean isProduction() { return isProduction; }

public static void setProduction(boolean isProduction) {
ClientUtil.isProduction = isProduction;

Now in every place in the code user ClientUtil.isProduction() to know if you are in production or not.


farquard said...

hey, great blog post, theres a pretty vital error where you say "in the production mode you would put this following line:" and theres nothing. Would be useful to know what that line is!

j2ee said...


Thanks for the comment,
actually I put "iframe" tag in the post so it wasn't shown in the post since iframe is hidden tag in html :)
I fixed it the error

Anonymous said...

Isn't calling GWT.isScript() a little cleaner? If it returns true, the you are running in "Production" mode, else you are running in hosted/development mode.

/r:b: said...

Also, there's a way to stub all your server side classes -- so you can develop in hosted mode without firing up Spring/Hibernate/database/whatever services:

or to see the url that goes to:

j2ee said...

Thanks for the comments,
You are write GWT.isScript is cleaner, I wasn't aware to this feature

ttidavi said...


I read this post two times.

I like it so much, please try to keep posting.

Let me introduce other material that may be good for our community.

Source: Production interview questions

Best regards


RSS Feeds Submission Directory