RSS

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

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

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

OR

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=”com.google.gwt.user.User”/>
<!– 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”/>
</module>

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

More info

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

Advertisements
 
14 Comments

Posted by on November 10, 2008 in GWT/ JSNI / COMPILER

 

Tags: , ,

14 responses to “GWT Compiler – Compiling for one browser and also supporting hosted mode

  1. batman

    December 2, 2008 at 12:59 pm

    oh, sweet – why have i only seen this now!!!

    thank you – this’ll make my day a bit easier 🙂

    kind regards

     
  2. jan berger

    December 16, 2008 at 3:54 pm

    awesome tip. this in combination with the default locale property speed my compilation up over 50%. thanks!

     
  3. Hicham

    March 4, 2009 at 10:01 am

    i want to compile for firefox but i received this error:

    [ERROR] Unable to load module entry point class org.vnf.itineo.client.Main (see associated exception for details)
    com.google.gwt.core.client.JavaScriptException: (TypeError): Cet objet ne gère pas cette propriété ou cette méthode
    number: -2146827850
    description: Cet objet ne gère pas cette propriété ou cette méthode
    at com.google.gwt.user.client.impl.DOMImplStandard.initEventSystem(Native Method)
    at com.google.gwt.user.client.impl.DOMImplMozilla.initEventSystem(DOMImplMozilla.java:45)
    at com.google.gwt.user.client.impl.DOMImpl.maybeInitializeEventSystem(DOMImpl.java:165)
    at com.google.gwt.user.client.impl.DOMImplStandard.sinkEvents(DOMImplStandard.java:160)
    at com.google.gwt.user.client.impl.DOMImplMozilla.sinkEvents(DOMImplMozilla.java:33)
    at com.google.gwt.user.client.DOM.sinkEvents(DOM.java:1214)
    at com.google.gwt.user.client.ui.UIObject.sinkEvents(UIObject.java:713)
    at com.google.gwt.user.client.ui.Image$UnclippedState.(Image.java:232)
    at com.google.gwt.user.client.ui.Image$UnclippedState.(Image.java:237)
    at com.google.gwt.user.client.ui.Image.(Image.java:354)

    thanks for your help

     
  4. Vinay

    March 4, 2009 at 10:20 am

    Hi Hicham,

    Please send me your module.gwt.xml….I think the problem is in your gwt file.

    or

    try this

    <!– 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

    thanks

     
  5. Hicham

    March 4, 2009 at 10:20 am

    thank you Vinay for thgis prompt response, mymodule.gwt.xml is as follow:

    <!– GWT locale
    –>

     
  6. Hicham

    March 4, 2009 at 10:29 am

    i tried your solution, but i got the same error, the module.gwt.xml is as follows:

     
  7. Itamar

    June 29, 2009 at 2:10 am

    Hello,
    I could not do the hosted mode working.
    Can you help me?
    itamarbel@gmail.com
    Thanks

     
  8. Vinay

    June 29, 2009 at 12:28 pm

    Hi, Could you please tell me which GWT version you are using

     
  9. Itamar

    July 1, 2009 at 3:17 am

    Hello Vinay, thanks for replying.
    I use the gwt version 1.5.3 with GXT version 1 .. 2.4, and also use the Maven.

     
  10. Vinay

    July 17, 2009 at 2:35 pm

    Sorry for the late response. I was not in my location

    is working in windows hosted mode [Don’t put other browser’s entry]
    Windows OS default browser is IE only. Hosted mode will take only OS default browsers.

    if you have any question please let me know

    thanks

     
  11. Gerardo Contijoch

    July 28, 2009 at 8:49 pm

    I’m afraid there’s a mistake in your post.
    You say that you can specify ‘user.agent’ property more than once in your Module.gwt.xml file and get compiled js for several browsers, which is not true. Only the last one will be the valid one.

    Using your sample code:

    you will get js compiled only for Firefox, and IE6 will be ignored.

    More info: http://code.google.com/intl/en-us/webtoolkit/doc/1.6/DevGuideOrganizingProjects.html (look for ‘Elements for Deferred Binding’)

     
  12. Vinay

    July 29, 2009 at 6:21 pm

    Hi,

    I have tested using 2 agents at a time in GWT 1.4.xx. I can see my screens in IE and Firefox. If I put one agent in my .gwt module I can see the output in IE only. Can you please check and let me know.

    thanks

     
  13. Gerardo Contijoch

    July 29, 2009 at 6:33 pm

    I’m using GWT 1.7 and the behavior is the one described in the documentation, that is, only the last ‘user.agent’ setting is valid.

    I wonder why did they removed such an useful feature…

     
  14. Vinay

    July 29, 2009 at 6:46 pm

    may be they are generating only minimal files for all ‘user.agent’

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: