GWT javascript后台加载

时间:2012-02-17 12:50:25

标签: java javascript gwt mobile

我使用GWT构建移动webapp。

当我在带有移动互联网连接的移动浏览器上调用应用程序时,由GWT生成的javascript加载需要很长时间。

所以,我想以这种方式改变它,我首先将一个Start HTML页面发送到客户端并在后台加载GWT-javascript。

这可能吗?

3 个答案:

答案 0 :(得分:2)

我认为你应该拆分你的代码,你可以在这里找到它:Developer's Guide - Code Splitting 如果您有大型应用程序,则必须使用它,否则整个应用程序(即JavaScript包)将在应用程序的初始加载时下载到一个块中。它可以帮助您减少初始代码下载。查看代码拆分后的结果: enter image description here

答案 1 :(得分:1)

我真的不知道移动应用程序,但在GWT应用程序中,javascript被加载到脚本标记内的html页面中:

<!--                                           -->
<!-- This script loads your compiled module.   -->
<!-- If you add any GWT meta tags, they must   -->
<!-- be added before this line.                -->
<!--                                           -->
<script type="text/javascript" language="javascript" src="application/application.nocache.js"></script>

如果您想在加载javascript之前出现任何内容,只需将其作为html放在该页面上即可。 例如:

<!--                                           -->
<!-- The body can have arbitrary html, or      -->
<!-- you can leave the body empty if you want  -->
<!-- to create a completely dynamic UI.        -->
<!--                                           -->
<body>

<!-- OPTIONAL: include this if you want history support -->
<iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>

<!-- RECOMMENDED if your web app will not function without JavaScript enabled -->
<noscript>
  <div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif">
    Your web browser must have JavaScript enabled
    in order for this application to display correctly.
  </div>
</noscript>

<!-- Loading indicator -->
<div id="loading">
  <div class="loading-indicator">
  <img src="images/loadingStar.gif" width="40" height="40" />Application Name<br />
<span id="loading-msg">Loading...</span></div>
</div>

<!--                                           -->
<!-- This script loads your compiled module.   -->
<!-- If you add any GWT meta tags, they must   -->
<!-- be added before this line.                -->
<!--                                           -->
<script type="text/javascript" language="javascript" src="application/application.nocache.js"></script>

这里,div标签将一个加载gif放在出现的页面上,直到加载了所有gwt javascript。在加载javascript之前,您可以在该页面上放置任何内容。

然后在您的应用程序中,(在模块加载时)用您的应用程序替换rootpanel的内容!!

答案 2 :(得分:1)

有两件事要做:

  1. 加快初始页面的加载:将<script>放在HTML页面的底部。

  2. 如果GWT代码很大,那么您可以将其拆分为较小的块并按需加载。如果您使用GWT code splitting,则会自动执行此操作。