如何在GWT离线应用程序中包含外部Javascript [英] How to include external Javascript in GWT offline application

查看:76
本文介绍了如何在GWT离线应用程序中包含外部Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个GWT(well,GXT)应用程序,它使用外部JavaScript库为我的应用程序添加功能。我的应用程序也必须脱机工作,这里是我的问题。



我知道,将文件添加到公用文件夹将使它们可以通过我的GWT应用程序访问,但是这在离线使用的情况下不起作用。 GWT编译我的应用程序使其可以在没有问题的情况下脱机使用,但它不包括外部JavaScript库。

所以,每当我在应用程序中工作并达到要点时在需要所述库的情况下,浏览器将尝试GET请求,因为该库尚未加载,并且不会可靠地保留在浏览器的缓存中。



有没有办法将库添加到我的应用程序,以便它将与我的GWT应用程序一起缓存?该库由几个文件夹,JS文件,图像,CSS等组成。我唯一的想法是动态创建一个Appcache Manifest,用于转储浏览器缓存中的所有文件。在这种情况下,我害怕打破GWT离线功能。

解决方案

是的,您可以在编译时生成清单。只需使用扩展com.google.gwt.core.ext.linker.AbstractLinker的链接器即可。



请参阅本例清单链接器< a>
或参阅
编写GWT链接器
或查看这个stackoverflow线程



我这样做包括谷歌字体,并产生一个清单,将只包含该特定语言排列的文件。


I have a GWT (well, GXT) application that uses an external JavaScript library to add functionality to my app. My application must work offline, too, and herein lies my problem.

I am aware that adding files to the public folder will make them accessible by my GWT app, but this will not work in case of offline use. GWT compiles my app to make it available offline without problem, but it doesn't include the external JavaScript library.

So, whenever I work within the application and reach the point where said library is needed, the browser will attempt a GET request because the library hasn't been loaded yet and doesn't remain in the cache of the browser reliably.

Is there a way to add the library to my app so that it will be cached together with my GWT app? The library consists of several folders, JS files, images, CSS, etc. My only idea is to dynamically create an Appcache Manifest that dumps ALL files in the browser cache.. in which case I'm scared of breaking the GWT offline functionality.

解决方案

Yes you can generate a manifest at compile time. Just use a linker that extends com.google.gwt.core.ext.linker.AbstractLinker.

See for example this example manifest linker or see Writing a GWT Linker or see this stackoverflow thread

I do that to include google fonts and to produce a manifest that will only include files for that specific language permutation.

这篇关于如何在GWT离线应用程序中包含外部Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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