【问题标题】:How to load nocache.js form html page other than default page?如何加载 nocache.js 表单 html 页面而不是默认页面?
【发布时间】:2013-10-01 12:26:25
【问题描述】:

我正在使用 GWT 技术开发一个 Web 应用程序。 但我在我的应用程序中面临加载时间问题。加载大约需要 1 分 30 秒。 仅当应用程序在任何浏览器上首次加载时才会遇到此问题。 发现添加到我的项目中的所有 *.js 都占用了最大时间。 我希望我的 index.html 必须首先加载,并且所有其他 html 和 .js 必须在任何按钮单击时加载。 为此,我想从 gwt 项目的默认 html 页面以外的页面加载我的 nocache.js。

提前感谢

【问题讨论】:

    标签: javascript html gwt no-cache


    【解决方案1】:

    您可以根据用户请求加载 gwt 应用,将一些 js 代码添加到您的 index.html 并从 html 按钮调用它:

      <script>
         function loadGWT() {
           var s = document.createElement('script');
           s.setAttribute('type','text/javascript');
           s.setAttribute('src',"mymodule.nocahe.js");
           document.body.appendChild(s);
         }
      </script>
      <button onClick='loadGWT()'>Load GWT App </button>
    

    [编辑]

    您必须使用 xsiframe 链接器而不是 standard 链接器。将此行添加到您的 .gwt.xml 文件中

      <add-linker name="xsiframe"/>
    

    【讨论】:

    • 因为标准链接器使用document.write,所以不能开箱即用。我认为xsiframe 是可以的,但也许只有启用它的一些隐藏功能(不记得了,没用过)
    • 你是对的 std 链接器不起作用,但 xs 和 xsiframe 工作正常。
    猜你喜欢
    • 1970-01-01
    • 2018-09-08
    • 1970-01-01
    • 1970-01-01
    • 2021-10-26
    • 1970-01-01
    • 2021-10-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多