gwt 编译为单个、整体的跨浏览器 html 文件

发布于 2024-09-26 14:42:22 字数 918 浏览 0 评论 0原文

我希望将我的 gwt 应用程序编译成一个单一的、整体的、跨浏览器兼容的 .html 文件。最终,我试图通过 gwt 设计一个 Amazon Mechanical Turk 模板。这些模板必须是单个 .html 文件,因为它们托管在 Amazon 的计算机上。 .html 文件可以引用外部源,但只能通过绝对地址引用,因为我无法控制文件层次结构。

我并不担心整体文件的加载速度比为每个浏览器使用单独的文件要慢。我正在开发一个相当简单的 Web 表单,仅包含极少数人会看到的客户端代码。因此,速度和跨浏览器正确性并不是主要考虑的问题。

我发现通过将以下行添加到我的 MODULE_NAME.gwt.xml 中,我可以生成一个专门用于单个浏览器(例如 firefox,如下所示)的 JavaScript 文件:

<set-property name="user.agent" value="gecko">

然后我将生成的代码嵌入到我的 .html 文件中,它适用于指定的单个浏览器。不幸的是,当我尝试在其他浏览器中打开 .html 文件时,gwt 生成的 javascript 不会加载。

是否有一个链接器命令可以添加到该文件中来实现这一目的?我尝试通过以下方式调用 SingleScriptLinker:

  <add-linker name="sso" />

但出现以下错误:

[错误] 该模块必须完全具有 使用时的一种不同排列 单脚本链接器。

我还尝试调整生成的 javascript 文件的内容,以使它们足够兼容以嵌入 .html 文件中,但 gwt 生成的 javascript 太混乱(即使在详细输出模式下)。有关于如何执行此操作的演练吗?

我在 OSX 上使用 gwt eclipse 插件。

I am looking to compile my gwt application into a single, monolithic, cross-browser compatible .html file. Ultimately, I'm trying to design an Amazon mechanical turk template via gwt. These templates must be a single .html file, since they are hosted on Amazon's machines. The .html file can reference external sources, but via absolute address only since I have no control over the file hierarchy.

It does not concern me that the monolithic file will load slower than having separate files for each browser. I am developing a fairly simple web form containing only client-side code that will be seen by very few people. Therefore, speed and cross-browser correctness are not primary concerns.

I have found that by adding the following line to my MODULE_NAME.gwt.xml I can generate a single javascript file that works exclusively for a single browser (e.g. firefox as shown below):

<set-property name="user.agent" value="gecko">

I then embed the generated code into my .html file, and it works for the single browser specified. Unfortunately, when I try opening the .html file in other browsers, the gwt generated javascript does not load.

Is there a linker command that I can add to this file that will do the trick? I tried to invoke the SingleScriptLinker via:

  <add-linker name="sso" />

but got the following error:

[ERROR] The module must have exactly
one distinct permutation when using
the Single Script Linker.

I also attempted to tweak the contents of the generated javascript files in order to make them compatible enough to embed in the .html file, but the javascript generated by gwt is too confusing (even in the detailed output mode). Is there a walk-through for how to do this?

I'm using the gwt eclipse plugin on OSX.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光沙漏 2024-10-03 14:42:22

幸运的是,我在发布问题后很快就找到了解决方法:
http://groups.google.com/group/Google-Web -Toolkit/browse_thread/thread/79e9634110487490

简而言之,答案是使用跨站脚本。

  • 将以下行添加到 MODULE_NAME.gwt.xml:

    < add-linker name="xs" />

gwt 将生成 MODULE_NAME.nocache.js 文件以及一些 MD5.cache.js 文件(请注意,MD5 文件以 .js 结尾,而不是 .html)。

  • 编译您的应用程序

  • 现在,将所有这些 .js 文件放在服务器 A 上。

  • 修改您的 MODULE_NAME.html 文件包含对服务器 A 上的 MODULE_NAME.nocache.js 的绝对引用。

  • 上传 MODULE_NAME .html 到服务器 B。

跨站点链接器使一切正常。

As luck would have it, I have found a workaround soon after posting my question:
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/79e9634110487490

In short, the answer is to use cross-site scripting.

  • Add the following line to MODULE_NAME.gwt.xml:

    < add-linker name="xs" />

gwt will generate a MODULE_NAME.nocache.js file as well as some MD5.cache.js files (note the MD5 files end with .js, not .html).

  • Compile your application

  • Now, put all of these .js files on server A.

  • Modify your MODULE_NAME.html file to contain an absolute reference to MODULE_NAME.nocache.js on server A.

  • Upload MODULE_NAME.html to server B.

The cross-site linker makes everything work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文