OpenSource For You

Code splitting

-

TKH VLzH RI Dn A-A; DSSOLFDWLR­n’V finDO RXWSXW RI -DvDSFULSW increases with the complexity of the applicatio­n. This, in turn, increases the applicatio­n’s initial load time. Since the applicatio­n will try to download the entire gavaScript content during initial loading, the applicatio­n start-up time will increase. The code splitting methodolog­y provides a way to GHfinH D SDUW RI WKH DSSOLFDWLR­n WR EH GRwnORDGHG LnLWLDOOy; other parts of the applicatio­n will be downloaded on demand. For instance, during the initial loading of an applicatio­n, only the gavaScript required for the login page of the applicatio­n is needed. lnly if the user successful­ly logs into the applicatio­n will the next page’s gavaScript content be downloaded. rntil then, the gavaScript content of the home page or other internal modules is not required or used. //Ior manual loaGinJ Ey FonfiJurin­J in *.JwW.xml file <exWenG-FonfiJuraW­ion-SroSerWy name ”FomSiler.sSliWSoinW.iniWial. seTuenFe” value ”Fom.name.oI.Whe.Flass”/> //Ior SroJrammaW­iF FonfiJuraW­ion GWT.run$synF(new Run$synF&allEaFN() { @2verriGe public void onpuccess() {

// /oaG ForresSonG­inJ moGule or seJmenW } @2verriGe SuEliF voiG on)ailure(ThrowaEle reason) {

// Can occur due to network failure or server unavailabi­lity.

} });

UVLnJ WKH FRGH-VSOLWWLnJ DSSURDFK, wH FDn GHfinH WKH modules that need to be downloaded initially by default, and DOO RWKHU PRGXOHV FDn EH FRnfiJXUHG WR GRwnORDG Rn GHPDnG, GXULnJ WKH fiUVW vLVLW. TKLV UHGXFHV VWDUW-XS WLPH, DnG RSWLPLVHV the performanc­e of the applicatio­n.

To split the code, insert a GtT.runAsync() block into the required pageLview initialisa­tion of the applicatio­n. This runAsync implements a ounAsyncCa­llback interface, which annotates the GWT compiler to create a separate module for the part covered in the block. Hence, the initial download will not LnFOXGH WKH FRnWHnW IRU WKH PRGXOH GHfinHG Ln AVynF EORFN. BXW LI WKH LnLWLDO ORDG UHTXLUHV VRPH SDUW GHfinHG Ln DnRWKHU AVynF block, it will be downloaded automatica­lly during initial load. Hence, care has to be taken while initialisi­ng split points to not PLx GLIIHUHnW PRGXOHV. :H FDn HvHn PDnXDOOy GHfinH WKH ORDG VHTXHnFH Ey GHfinLnJ WKHP Ln WKH PRGXOH GHVFULSWRU fiOH.

Newspapers in English

Newspapers from India