Monday, July 7th, 2008

Exploring GWT Linkers

Category: GWT

Alex Moffat has written up an exploration of GWT linkers. It looks at the linking part of the GWT compilation step using as an example a linker that creates a sort of manifest for the JavaScript files created by compilation so that you can easily tell which file goes with which browser/locale/etc. combination.

In GWT 1.5 the build process is internally divided into two phases, compilation, which creates JavaScript from Java, and linking, which takes the JavaScript and other resources produced by the compilation phase and packages it for deployment. I wanted to understand a bit more about the linking process after seeing Bob Vawter talk about Resource Bundles and Linkers in GWT at the Google I/O conference. To try and help me do that I’ve created a linker that you can include in you build process to create a sort of manifest file listing which generated JavaScript file applies to which permutation of browser, locale etc.

To create a linker and have it called during the build process you need to do four things

  • Create a class that implements
  • Add a LinkerOrder annotation to the class to define whether the linker should run before the primary linker, after the primary linker or instead of the primary linker. You’re allowed as many linkers before and after the primary as you like but only one primary linker.
  • Define and add the linker in a <module>.gwt.xml file.
  • Include the new class in the classpath when running the gwt compiler.

The 1.5 RC1 build provides three different primary linkers that produce three different ways of packaging the compiler output for loading by the browser. The standard linker produces the familiar <module>.nocache.js file that loads the correct <strong name>.cache.html for the target browser. This is the linker that is added in Core.gwt.xml and so is the default linker that is used. Also provided are a cross site linker that creates a <module>-xs.nocache.js and a single script linker. You use the cross site linker if you need to host the GWT generated artifacts on a separate domain from your main site, for example if you use for serving dynamic content and put all the static stuff, including JavaScript, on The single script linker can be used when the compilation process always creates a single JavaScript file that is applicable to all permutations.

Posted by Dion Almaer at 6:33 am
Comment here

3.6 rating from 15 votes

Comments Here »

Comments feed TrackBack URI

Leave a comment

You must be logged in to post a comment.