You've probably heard of Google Web Toolkit (GWT), which supports writing Web applications in the Java™ programming language, and then compiling the Web application into JavaScript to run in a Web browser. This allows for increased productivity through the use of excellent tools such as static types of Java and Eclipse. You may have seen some of the useful, popular widgets built on GWT. One thing you may not know, GWT supports creating high-performance Web applications.
Prerequisite
This article looks at several GWT features and how these features can help you build high-performance Web applications. This article is not a GWT profile, we assume you have GWT experience. This article also assumes that you understand Java technology and are familiar with JavaScript, CSS, and HTML. This article uses Google Plug-in for Eclipse, using the version of Google Plug-in V1.1 and Eclipse V3.5 (Galileo). This article also uses Firebug plug-in for Mozilla Firefox, with versions for Firebug V1.4.2 and Firefox V3.5.2.
Faster JavaScript
GWT is renowned for its ability to compile Java into JavaScript, enabling developers to develop dynamic WEB applications. Many of the performance features that all code compiles to JAVASCRIPT,GWT are designed to make JavaScript run faster in the browser. There are several features in GWT that include browser-specific optimizations and simplified Ajax, but most of the features come from GWT's Java-to-javascript compiler. So we'll start with this compiler to explore GWT's performance-related features.
Compiler optimizations
The GWT compiler will convert your Java code to JavaScript that runs in the browser, but it does more than that, and it also makes a lot of optimizations to make your code run faster. However, it is difficult to accurately understand the detailed process of these optimizations because the JavaScript emitted by GWT is blurred and difficult to read. First, I want to instruct the GWT compiler to generate some readable JavaScript so that we can better understand the optimizations implemented by the compiler.
The GWT compiler has 3 modes of operation. The default mode is obfuscated, because the GWT compiler will emit vague JavaScript. This JavaScript is not only difficult to read, it is also compressed. This makes it smaller, allowing it to load quickly on the Internet. Smaller volumes also help browsers parse JavaScript more quickly.
You might think that sending compressed JavaScript over the network is nothing special, because most Web servers use the GZIP compression format to send JavaScript and all modern web browsers support the gzip format. However, the GWT compiler compresses not only JavaScript, but its compression also supports gzip compression in nature. In other words, despite being compressed, GWT's obfuscated JavaScript is still highly gzip-compressed. This way, if your WEB server does not use gzip, you can get a great speed boost by using the GWT blur feature. However, even if your WEB server uses gzip, you can get a noticeable speed boost from the GWT blur feature.
So for the production code, of course we want the GWT compiler set to emit fuzzy JavaScript. However, this obviously makes the emitted JavaScript almost unreadable. To illustrate this issue, check out some of the GWT Blur JavaScript in Listing 1.
Listing 1. Fuzzy JavaScript
function QH () {return NP}
function MH () {}
_=mh.prototype=new mu;_.gc=qh;_.ti=0;function
UH () {uh= ZH;SH={};TH=[];SH[LM]=[IS,HS,JS];SH[JM]=[RT,QT,ST]; Xv (TH,YN,LM); Xv (TH,TO,JM)}
Var sh,th;function AH (a) {A.b=oh (new MH); return a}
function BH (a) {var b,c,d,e,f,g,h,i,j,k;g=ox ( New cx,mm); F=oa (new FA); J=xh (new
Vh,nm,om); KA (F,J.B+SJ+J.C);p W (g.b,pm,true); Zw (GA (QM), f); Zw (GA (RM), g); F.b.focus ()
; K=JG (F.B,NJ). Length;k>0&&ja (F,0,k); C=py (new My); Lf (TF (), c.b.b), SM); c.o=true;
B=ox (New Cx,tm), B.b.id=um;i=py (new Ny), H=ty (new My);d =ua (new RA);p W (d.b,vm,true);
VA (D,uy (new MY,WM)); VA (D,i); VA (D,uy (new MY,XM)); VA (d,h);d. b= (KZ (), JZ); VA (D,B);
Ax (c.j,d); Mx (c); VW (B,FH (new dh,c,g), (SH (), RH); E=kh (new ih,a,g,f,i,h,c,b);
VW (G,E,RH); VW (F,e, HI (), GI)}
Function CH () {return RP}
Function XH () {}
Fortunately, it's easy to "spoof" the GWT compiler to create some human-readable JavaScript. This simply passes a-style=pretty parameter to the compiler, which can be easily done using Google Plug-in for Eclipse. When you trigger a GWT compilation, a dialog box like the one shown in Figure 1 is displayed.
Figure 1. GWT Compiler Options