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.