5

http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=google-web-toolkit-doc-1-5&t=FAQ_CompileOnePermutation

In the article I learned I can speed up the compiler but specifying the target user agent. The problem how can I specify more than one user agent? Suppose my application supports ie6 and FF3

<set-property name="user.agent" value="ie6,geck1_8" />

doesn't work - I got XML parsing error:

[ERROR] Invalid property value 'ie6,gecko1_8'

I'm wondering if there's a way to specify more than one specific user agent in the module XML file?

5 Answers5

6

I've had a similar error message, when setting the user.agent value to gecko in GWT2.4. So I looked around and found where the gwt code defines the possible values.

If you look in the gwt-user.jar at com.google.gwt.user.UserAgent.gwt.xml you can see the possible values for the version of GWT you are using.

For GWT2.4, this is what i found:

<!-- Browser-sensitive code should use the 'user.agent' property -->
  <define-property name="user.agent" values="ie6" />
  <extend-property name="user.agent" values="ie8" />
  <extend-property name="user.agent" values="gecko1_8" />
  <extend-property name="user.agent" values="safari" />
  <extend-property name="user.agent" values="opera" />
  <extend-property name="user.agent" values="ie9" fallback-value="ie8" />
  <property-provider name="user.agent" generator="com.google.gwt.user.rebind.UserAgentPropertyGenerator"/>

Therefore gecko is not a valid value for user.agent in my case, and if I use gecko1_8 it compiles for Firefox fine.

  • I noticed in GWT 2.7.0 that the UserAgent.gwt.xml is now in the gwt-user.jar at com.google.gwt.useragent –  May 12 '15 at 09:17
6

for webkit based browsers like chrome, use "safari" as the user agent

Swapnil
  • 897
  • 7
  • 15
6

Works in GWT 1.6, your *.gwt.xml file :

<module rename-to="moduleName">
      <!-- blah blah -->
      <set-property name="user.agent" value="ie6,gecko,gecko1_8" />
      <!-- generate perms for IE and firefox only -->
</module>
ShashiKant
  • 210
  • 2
  • 8
  • Is that IE6 only, or would it compile JS for all versions of IE? – Adam Parkin Jan 06 '14 at 18:55
  • 1
    That is IE6 only. There are other constants defined for the other IE: IE8, IE9, IE10. See the GWT source: https://gwt.googlesource.com/gwt/+/master/user/src/com/google/gwt/useragent/UserAgent.gwt.xml – Bdoserror Jun 03 '14 at 17:38
4

In order to rapidly deploy any application, you'll need two targets; once for the engine your hosted mode deploys on {Firefox / Linux, Safari / Mac, IE6 / Win}, and one for your agile browser that lets you build css in real-time {Firefox + Firebug}.

Linux: <set-property name="user.agent" value="gecko1_8,gecko"/>
Mac: <set-property name="user.agent" value="gecko1_8,safari"/>
...etc...

This is GWT >= 1.6 ONLY!

For older gwt projects, you must super-source the com/google/gwt/user/UserAgent.gwt.xml file... Put it in a source location that is included BEFORE your gwt-*.jar on the classpath. Basically, you can copy that file into a new one in the same package as the original, and edit the CDATA javascript block that returns the actual user.agent value. Play with this all you like, but don't go getting too crazy with their user.agent property, as it WILL be changing for ie8 in a future build.

To target ie browsers, make up your own ie.version property, and tweak a copy of the property-provider in UserAgent.gwt.xml to target different versions of ie. Just make sure that when you use the custom property for deferred binding you do:

<all>
  <when-property-is name="user.agent" value="ie6"/>
  <any>
    <when-property-is name="ie.version" value="ie7"/>
    <when-property-is name="ie.version" value="ie8"/>
  </any>
</all>

Or you'll get ie7 + gecko/safari builds and other silly junk that will never be used.

Note: Any code in a property-provider is loaded in the .nocache.js, and can be useful to preload images / css whilst the .cache.js payload is being downloaded.
Just add var __cached = new Image('Url To Compiled Image / Whatever you want to load');

1

Not yet. The idea is that you develop rapidly to one browser and then compile once to deploy (i.e., do final testing) for all browsers, with GWT handling the browser differences. Don't forget that at deploy time GWT will optimize the downloads per browser so that in the end it doesn't matter how many user agents you chose.

Glenn
  • 6,455
  • 4
  • 33
  • 42