Code split­ting

OpenSource For You - - DEVELOPERS OVERVIEW -

TKH VLzH RI Dn A-A; DSSOLFDWLRn’V finDO RXWSXW RI -DvDSFULSW in­creases with the com­plex­ity of the ap­pli­ca­tion. This, in turn, in­creases the ap­pli­ca­tion’s ini­tial load time. Since the ap­pli­ca­tion will try to down­load the en­tire gavaScript con­tent dur­ing ini­tial load­ing, the ap­pli­ca­tion start-up time will in­crease. The code split­ting method­ol­ogy pro­vides a way to GHfinH D SDUW RI WKH DSSOLFDWLRn WR EH GRwnORDGHG LnLWLDOOy; other parts of the ap­pli­ca­tion will be down­loaded on de­mand. For in­stance, dur­ing the ini­tial load­ing of an ap­pli­ca­tion, only the gavaScript re­quired for the lo­gin page of the ap­pli­ca­tion is needed. lnly if the user suc­cess­fully logs into the ap­pli­ca­tion will the next page’s gavaScript con­tent be down­loaded. rn­til then, the gavaScript con­tent of the home page or other in­ter­nal mod­ules is not re­quired or used. //Ior man­ual loaGinJ Ey Fon­fiJur­inJ in *.JwW.xml file <exWenG-Fon­fiJu­raWion-SroSerWy name ”­iWial. seTuenFe” value ””/> //Ior SroJram­maWiF Fon­fiJu­raWion$synF(new Run$synF&al­lEaFN() { @2ver­riGe pub­lic void on­puc­cess() {

// /oaG For­resSonGinJ moGule or seJ­menW } @2ver­riGe SuEliF voiG on)ail­ure(ThrowaEle rea­son) {

// Can oc­cur due to net­work fail­ure or server un­avail­abil­ity.

} });

UVLnJ WKH FRGH-VSOLWWLnJ DSSURDFK, wH FDn GHfinH WKH mod­ules that need to be down­loaded ini­tially by de­fault, and DOO RWKHU PRGXOHV FDn EH FRn­fiJXUHG WR GRwnORDG Rn GHPDnG, GXULnJ WKH fiUVW vLVLW. TKLV UHGXFHV VWDUW-XS WLPH, DnG RSWLPLVHV the per­for­mance of the ap­pli­ca­tion.

To split the code, in­sert a GtT.runAsync() block into the re­quired pageLview ini­tial­i­sa­tion of the ap­pli­ca­tion. This runAsync im­ple­ments a ounAsyncCall­back in­ter­face, which an­no­tates the GWT com­piler to cre­ate a sep­a­rate mod­ule for the part cov­ered in the block. Hence, the ini­tial down­load 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 down­loaded au­to­mat­i­cally dur­ing ini­tial load. Hence, care has to be taken while ini­tial­is­ing 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

© PressReader. All rights reserved.