Wednesday, August 17, 2011

GWT Introduction

GWT stands for Google web toolkit.GWT is a toolkit that helps in building a web application. The typical steps of building an application using GWT is

  • Write the Java code.
  • GWT compiler compiles it into Javascript
  • The Javascript code runs on the client.
This is the major difference that GWT brings on table in terms of application building is that, the code is written in Java and GWT compiles it into Javascript. The advantage of such an approach is, the application speed is much faster as the code in javascript primarily runs on the browser. A small discussion can be seen here about when to choose what kind of frameworks. GWT is a very good choice if the need is to build Rich application with desktop like capabilities.

GWT generates javascript code for each variation of browser and locale. So for example if there are three browser types and four languages supportes, GWT will generate twelve sets of javascript code to handle all the variation. It leads to some work upfront, but at runtime this results in a much better performance.

The core element of GWT is the compiler which generates Java to Javascript. GWT does a monolithic compilation of Java code to generate the Javascript. What it means is that GWT will look into the whole code base to generate the Javascript. This helps in doing certain optimizations.
GWT can do following optimizations while generating the Javascript code.
  • GWT will remove the code that is not getting called from anywhere.
  • GWT compiler will do the inlining of the small functions.
  • GWT will intern the strings and reuse them.
  • GWT will replace the variables with constants, wherever possible. For example if i=3*2, GWT will replace with i=6.

Another important component of GWT is the JRE emulation library. It is a small subset of JRE to handle the Java to Javascript conversion. This of the JRE emulation library as representing the Javascript capabilities.

Disadvantages
  • GWT generated pages are not SEO friendly as they are generated dynamically, so the indexing cannot be done. Cloaking can be used, which means maintaining two sets of pages to help in indexing however it soon becomes unmaintainable.
  • GWT either works on or fails completely in a browser. This is especially true for olde version of browsers. Though GWT team strives hard to achieve the support for all variations of browser, but still.
  • Hand written code in direct javascript will be faster than GWT but it would require a very high level of proficiency in Javascript including intricate understanding of all the browser quirks in handling javascript.

No comments:

Post a Comment