2012-02-17 40 views
0

我使用GWT构建移动Web应用程序。GWT javascript background loading

当我通过移动互联网连接在移动浏览器上调用应用程序时,由GWT生成的JavaScript加载花费很长时间。

所以,我想改变它,我首先发送一个开始的HTML页面到客户端,并在后台加载GWT-javascript。

这可能吗?

回答

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出现在页面上的JavaScript之前已加载所有的GWT。加载javascript之前,您可以在该页面上放置任何您想要的内容。

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

+0

我这样做就像你在你的答案中提到的一样。但问题仍然存在。问题是加载图标是在onModuleLoad()上删除,但我的网站页面变为空白,然后5-6秒页面显示。我已经在使用代码分割技术,但问题仍然存在。你可以帮我吗 ?网站链接是[enggheads.com](https://www.enggheads.com),你可以检查出来 – 2016-05-19 07:05:39

2

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

+0

你甚至可以告诉应用程序预载下一个片段,甚至在你的用户决定继续通过开始屏幕之前。 GWT开发者指南有例子。 – 2012-09-23 02:39:55

1

有两两件事要做:

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

  2. 如果GWT代码很大,那么你可以把它分成更小的块并按需加载。如果您使用GWT code splitting,则会自动发生。