简体   繁体   English

带有外部Javascript脚本的GWT库

[英]GWT library with external Javascript script

I wrote an GWT library for a javascript visualization library ( dygraphs ). 我为javascript可视化库( dygraphs )编写了一个GWT库。
It's a simple wrapper using JavascriptObject and JSNI to call into the dygraphs code. 它是一个简单的包装器,使用JavascriptObjectJSNI调用dygraphs代码。
So far I have included the dygraphs.js script in my GWT's module xml file and it worked just fine. 到目前为止,我已经在我的GWT的模块xml文件中包含了dygraphs.js脚本,它运行得很好。

However when I recently tried to use SuperDevMode I had to switch to the xsiframe linker which doesn't allow script tags. 但是,当我最近尝试使用SuperDevMode我不得不切换到不允许脚本标记的xsiframe linker
What is the best practice for including external javascript scripts in a GWT library with the cross site linker? 使用跨站点链接器在GWT库中包含外部JavaScript脚本的最佳实践是什么?

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? 我能想到的最好的事情是将Javascript文件作为TextResourceClientBundle ,然后使用ScriptInjector来包含它?

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. 在使用我的GWT包装器的应用程序将访问它之前,我必须确保dygraphs.js已完全加载。

Including your external javascript as a TextResource and injecting it yourself is a very good way making sure its loaded with your app. 将您的外部JavaScript作为TextResource包含并自己注入是确保其加载您的应用程序的一种非常好的方法。 (and you are saving the extra http request while benefitting from GWT cache mechanism) (并且您正在保存额外的http请求,同时受益于GWT缓存机制)

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. 如果您在瘦客户端上运行,您可能希望将DOM中的实际注入与解析分开,如果您从上到下注入带有注释的textresource,然后再将其删除,则可以轻松完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM