Question

There's no Code Splitting option When I create PresenterWidget in Eclipse, so I assume that my PresenterWidget or DialogBox (that is initiated in HeaderPresenter) will be downloaded at the time the HeaderPresenter is called. Let see this code in HeaderPresenter:

Button b = new Button("Click me", new ClickHandler() {
  public void onClick(ClickEvent event) {
    MyDialogBox myD=new MyDialogBox(); ///There a lot of Gui (button, grid, css...) on this dialogbox
    myD.show();
  }
});

So, my first question is:

1st, Will the webapp download all the GUI of MyDialogBox when user comes to page Header?

2nd, Suppose users come to page Header second time on the same browser & also the SAME session, then will the webapp download all the GUI of MyDialogBox? (if it is on the same session, then i believe it won't download again since the GUI got Catch elsewhere)

Ok, now I will put this Code Splitting as suggested by Google http://www.gwtproject.org/doc/latest/DevGuideCodeSplitting.html, as following:

Button b = new Button("Click me", new ClickHandler() {
  public void onClick(ClickEvent event) {
    GWT.runAsync(new RunAsyncCallback() {
      public void onFailure(Throwable caught) {
        Window.alert("Code download failed");
      }

      public void onSuccess() {
        MyDialogBox myD=new MyDialogBox(); ///There a lot of Gui (button, grid, css...) on this dialogbox
        myD.show();
      }
    });
  }
});

My assumption is that the Webapp will not download this code whenever user visits Header page. But it will download the code on when users click the button "b". But my question is that

If you click the button first time, then it will download, but what if user clicks the same button 2nd time or even 3rd time, then will the app continue to download the same GUI of DialogBox in 2nd/3rd time? or Will the app catch the GUI of the DialogBox elsewhere when it downloaded 1st time & when user clicks 2nd/3rd time it will recall the catch rather than downloading the same things again?

I am confused, can anyone clarify?

Also, is it worthy to do code splitting for big DialogBox?

Was it helpful?

Solution

  • Code-splitting only downloads the stuff the first time it is required, so dont worry about it since the user will have a good experience because: code is loaded once per session , and split fragment is cached in browser for ever because its unique name.

  • The number of splits you have to do in your application depends on different things, one is if the amount of code in each fragment is big enough, another is that you have users who access to one part of the application (id admin screens) and you don't want others to load the fragment always, maybe you want a fast loading of the login screen, etc. So if this big DialogBox you mention is used by all users always, I would not split it, unless there are other reasons like fast loading of the page the first time.

  • I recommend taking a look to the compile-report output, so as you can see what is the amount of code in each fragment, and whether it is worth to have each split point in your code.

  • Finally there is a new feature in the compiler which is called fragmentCount and playing with this you can optimize the number of fragments in your app.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top