Sep 22, 2009

GWT Compiler - Compiling for one browser and also supporting hosted mode

When you want to compile your GWT module for only specific browser, you can change UserAgent.gwt.xml inside gwt-user.jar in package

Find this text and change it as you wish:
<define-property name="user.agent" values="ie6,gecko,gecko1_8,safari,opera">

gecko - Mozilla ,gecko1_8 - FireFox

I want to compile for only IE , then I change it into
<define-property name="user.agent" values="ie6">
I want to do this because we limit specification of browser for our application, and by doing this we can get more space up to 40%

GWT spends time to compute permutations : create javascript file per browser/locale. With this kind of application, GWT produces 50 permutations :
  • 5 browsers : ie6, opera, gecko1_8, safari, gecko
  • 10 locales : default, de_DE, en_UK, fr_FR, hr_HR, hu_HU, it_IT, nl_NL, pl_PL, pt_PT

1) Force a single browser

You can add the following set-property in ModuleName.gwt.xml

<!-- User Agent -->

<set-property name="user.agent" value="xxxx" />
where value = "ie6/opera/gecko1_8/safari/gecko"

Note: Add only one User Agent set-property in your ModuleName.gwt.xml
For example in MODULE com\mymodule\Container.gwt.xml:
<module >
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name=""/>
<!-- Inherit the GWT-EXT stuff. -->
<inherits name="com.gwtext.GwtExt" />
<!-- Inherit the GWT-EXT User Extension stuff. -->
<inherits name="com.gwtextux.GwtExtUx" />
<inherits name="com.gwtextux.GridSearchPlugin"/>
<!-- User Agent -->
<set-property name="user.agent" value="ie6" />
<!-- Include the core ExtJs files. -->
<stylesheet src="js/ext/resources/css/ext-all.css" />
<script src="js/ext/adapter/ext/ext-base.js" />
<script src="js/ext/ext-all.js" />
<script src="js/pagebus/pagebus.js"/>

2) Use only one locale

By default, GWT uses "default" locale. So no need to worry about the locale settings.

By doing this you can see the files difference in MODULENAME/html/*.* (If you are using Cypal Studio) MODULENAME/www/*.* (If you are using GWT Designer) before and after added the set-property in ModuleName.gwt.xml

With this two points, GWT really speeds up we can get more space up to 30% to 40% and compilation timewill be almost 40% less.

Compile GWT files more than one browser

If you add user.agent=ie6 the compiled code will work only in IE6.

If you add the following user.agent then your code will work both the browsers (IE6 & Firefox 2/3)

<!– User Agent –>

<set-property name=”user.agent” value=”ie6″/>

<set-property name=”user.agent” value=”gecko1_8″/ >

If you add

<set-property name=”user.agent” value=”ie6,gecko1_8″/>

you will get an error message like below

[ERROR] Invalid property value ‘ie6,gecko1_8′

[ERROR] Failure while parsing XML


Before “user.agent”

Before Script Added

After “user.agent” added

after Script Added

More info

Javascript Debug Toolkit – Debug javascript in ie,firefox,chrome,safari,opera and all browsers support ajaxToo


Kai Wähner said...

Hey there,

great post. But one problem:

Unfortunatelly, this does not work :-(

The GWT Compiler still creates just one permutations? Any advice?

Vinay said...

Hi Kai,
This post is useful for those who are using GWT 1.4.6x. I think you are using latest GWT. No need to use this optimization techniques.


Text Widget

Copyright © Vinay's Blog | Powered by Blogger

Design by | Blogger Theme by