将GWT应用程序部署为单个JavaScript文件 [英] Deploy GWT Application as Single JavaScript File

查看:129
本文介绍了将GWT应用程序部署为单个JavaScript文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GWT应用程序的已编译JavaScript输出分为多个文件,例如


  • *。cache.html

  • *。gwt.rpc

  • hosted.html

  • *。nocache.js



...



我知道这是为了尽量减少JavaScript的大小,必须由用户下载。例如,以便Firefox用户不必加载专门为IE6编译的JavaScript。

然而,特别是对于小型GWT应用程序,下载单个应用程序通常会更快例如500kb的文件,而不是先为5kb * .nocache.js脚本创建两个连续的请求,然后再为应用程序的其余部分(cache.html文件等)创建两个连续的请求。



这引出了一个问题:是否有任何框架或过程将GWT编译器的输出捆绑到单个JavaScript文件中

解决方案

首先,您可以使用所谓的soft permutations

然后,您可以将* .nocache.js内联到HTML主机页面(例如,使用JSP的 @include 指令)以减少一个额外请求(您可能需要添加一个< meta name = gwt:property content ='baseUrl = myapp'> 其中 myapp 是子文件夹,其中 .nocache。文件位于)。
AFAIK这就是Google为他们的GWT应用程序所做的事情。 另外,您也可以如果您可以完全替换选择脚本(* .nocache.js)和服务器端内容协商(基于User-Agent和Accept-Language请求标头,请在服务器端运行 permutation selection 实例),可以直接为t生成一个< script> 标记他适当的* .cache.js文件(提供您使用 xsiframe 链接器)。



AFAIK,Google全部使用这些技巧适用于他们的GWT应用程序(例如Google Groups)。但对于一个小应用程序,我不确定这是否值得付出努力...

另外,当您的HTML主机页面已经是动态的并且因此已经不可缓存时,最后两种技术效果最好;否则你主要是解决问题,而不是解决它。



我想知道是否可以使用 sso 链接器当你将所有属性和软排列折叠成单个硬排列。


The compiled JavaScript output of a GWT application is divided into various files, for instance

  • *.cache.html
  • *.gwt.rpc
  • hosted.html
  • *.nocache.js

...

I know this is done with the purpose of minimizing the size of the JavaScript, which has to be downloaded by users. For instance so that a Firefox user does not have to load the JavaScript specifically compiled for IE6.

However, especially for small GWT applications it might often be faster to download a single file of say 500kb rather than make two sequential requests first for the 5kb *.nocache.js script and then for the rest of the app (cache.html files, etc.).

This leads me to the question: Is there any framework or procedure to bundle the output of the GWT compiler into a single JavaScript file?

解决方案

First, you can merge all permutations in a single file by using so-called "soft permutations".

Then, you can inline your *.nocache.js into the HTML host page (e.g. using a JSP's @include directive) to cut one additional request (you might have to add a <meta name=gwt:property content='baseUrl=myapp'> where myapp is the subfolder where the .nocache. files are located).
AFAIK that's what Google are doing for their GWT apps.

Alternatively, you can run the permutation selection on the server-side if you can totally replace the selection script (*.nocache.js) with server-side content negotiation (based on User-Agent and Accept-Language request headers for instance) that can directly generates a <script> tag for the appropriate *.cache.js file (provided you use the xsiframe linker).

AFAIK, Google use all these techniques for their GWT apps (such as Google Groups). For a small app, though, I'm not sure it's worth the effort…
Also, the last two techniques work best when your HTML host page is already dynamic and therefore already non-cacheable; otherwise you're mostly moving the problem, not solving it.

I wonder whether the sso linker can be used when you collapse all properties and soft-permutations down to a single hard permutation.

这篇关于将GWT应用程序部署为单个JavaScript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆