我们使用 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/