java - GWT cache.js 太大——应用程序需要一些时间才能显示

标签 java gwt errai

我们使用 GWT 之上的 JBoss Errai 框架来构建 Web 应用程序。我们遇到的问题是,经过优化编译后,应用程序的编译版本大小已约为 10 MB。

有没有办法让 GWT/Errai 应用程序在加载 while cache.js 文件之前分割或以某种方式显示初始页面?

最佳答案

您可以使用Code Splitting机制。

To split your code, simply insert calls to the method GWT.runAsync at the places where you want the program to be able to pause for downloading more code. These locations are called split points.

例如:

public class Hello implements EntryPoint {
  public void onModuleLoad() {
    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() {
            Window.alert("Hello, AJAX");
          }
        });
      }
    });

    RootPanel.get().add(b);
  }
}

... the code initially downloaded does not include the string "Hello, AJAX" nor any code necessary to implement Window.alert. Once the button is clicked, the call to GWT.runAsync will be reached, and that code will start downloading. Assuming it downloads successfully, the onSuccess method will be called; since the necessary code has downloaded, that call will succeed. If there is a failure to download the code, then onFailure will be invoked.

您可以在文档中找到详细信息:http://www.gwtproject.org/doc/latest/DevGuideCodeSplitting.html

关于java - GWT cache.js 太大——应用程序需要一些时间才能显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42480851/

相关文章:

java - 如何解决此 PicasawebService 错误?

java - 在jetty9上使用xml部署war文件

applet - JDK 6 和 Linux

java - GWT 远程过程调用。在两个模块之间共享 RPC 服务

java - 如何将参数自定义 View 传递给 Activity 类

javascript - 声音未播放

css - GWT: anchor margin

java - NoClassDefFoundError : javax/inject/Provider and ClassNotFoundException: javax. 注入(inject).Provider

java - Errai JAX-RS - 未找到用于 POST 的资源方法,返回带有 Allow header 的 405

java - CDI 事件未触发