带有外部Javascript脚本的GWT库 [英] GWT library with external Javascript script

查看:105
本文介绍了带有外部Javascript脚本的GWT库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为JavaScript可视化库( dygraphs )编写了一个GWT库。

这是一个使用 JavascriptObject JSNI 调用dygraphs代码的简单包装。

到目前为止,在我的GWT的模块xml文件中包含了 dygraphs.js 脚本,它的工作原理就是
。然而,当我最近尝试使用 SuperDevMode 时,我不得不切换到 xsiframe链接器不允许使用脚本标记。

使用跨站点链接器在GWT库中包含外部javascript脚本的最佳做法是什么?



我能想到的最好的事情是在 ClientBundle TextResource $ c>,然后使用 ScriptInjector 包含它?

这是推荐的方法还是有更好的方法?



我必须确保在使用我的GWT包装器访问它的应用程序之前,dygraphs.js已完全加载。

解决方案

将外部JavaScript作为TextResource并自行注入是确保其与应用程序一起加载的一种非常好的方式。 (并且您在保存额外的http请求的同时受益于GWT缓存机制)



如果您在瘦客户端上运行,您可能需要将DOM中的实际注入从解析,如果你从上到下注入文本资源,然后删除它,你可以轻松地做到这一点。


I wrote an GWT library for a javascript visualization library (dygraphs).
It's a simple wrapper using JavascriptObject and JSNI to call into the dygraphs code.
So far I have included the dygraphs.js script in my GWT's module xml file and it worked just fine.

However when I recently tried to use SuperDevMode I had to switch to the xsiframe linker which doesn't allow script tags.
What is the best practice for including external javascript scripts in a GWT library with the cross site linker?

The best thing I could come up with was to include the Javascript file as a TextResource in a ClientBundle and then use ScriptInjector to include it?

Is that the recommended approach or is there any better way?

I have to make sure that the dygraphs.js is fully loaded before my app that is using my GWT wrapper is going to access it.

解决方案

Including your external javascript as a TextResource and injecting it yourself is a very good way making sure its loaded with your app. (and you are saving the extra http request while benefitting from GWT cache mechanism)

If you are running on thin client you may want to separate the actual injection in the DOM from parsing, which you could easily do if you inject the textresource with a comment from top to bottom and then later on remove it.

这篇关于带有外部Javascript脚本的GWT库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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