Code splitting
TKH VLzH RI Dn A-A; DSSOLFDWLRn’V finDO RXWSXW RI -DvDSFULSW increases with the complexity of the application. This, in turn, increases the application’s initial load time. Since the application will try to download the entire gavaScript content during initial loading, the application start-up time will increase. The code splitting methodology provides a way to GHfinH D SDUW RI WKH DSSOLFDWLRn WR EH GRwnORDGHG LnLWLDOOy; other parts of the application will be downloaded on demand. For instance, during the initial loading of an application, only the gavaScript required for the login page of the application is needed. lnly if the user successfully logs into the application 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 FonfiJurinJ in *.JwW.xml file <exWenG-FonfiJuraWion-SroSerWy name ”FomSiler.sSliWSoinW.iniWial. seTuenFe” value ”Fom.name.oI.Whe.Flass”/> //Ior SroJrammaWiF FonfiJuraWion GWT.run$synF(new Run$synF&allEaFN() { @2verriGe public void onpuccess() {
// /oaG ForresSonGinJ moGule or seJmenW } @2verriGe SuEliF voiG on)ailure(ThrowaEle reason) {
// Can occur due to network failure or server unavailability.
} });
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 performance of the application.
To split the code, insert a GtT.runAsync() block into the required pageLview initialisation of the application. This runAsync implements a ounAsyncCallback 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 automatically during initial load. Hence, care has to be taken while initialising split points to not PLx GLIIHUHnW PRGXOHV. :H FDn HvHn PDnXDOOy GHfinH WKH ORDG VHTXHnFH Ey GHfinLnJ WKHP Ln WKH PRGXOH GHVFULSWRU fiOH.