additional js library

We need to add some aditional js library to our mendix application. The only way to do this is by adding the js reference into the index.html. Because this library is really huge I wouldn't prefer to load this library in the theming. This is because the library is only needed in combination with a particular widget. Is there some way to include js libraries in your widget? Otherwise we have to load this js library each time. And will the js file be cached and/or gezipped?
3 answers

Best is to use the dojo loading mechanism. In top of the .js file of your library add:


and in the widget add on the top (or in the postCreate for lazy loading)


The advantage of this approach is (in contrast to Roelands approach) that dojo will make sure that the library is loaded before your widget, so that the widget can refer safely to it. Furthermore dojo ensures that the library will be load only once, even if multiple widgets refer to it. Simple chart provides indeed an example of this approach.

var myModuleLoad = mendix.dom.script({"src" : mx.moduleUrl("MyModule",'js/additional.js'), "id" : 'MyScript'});

this is wat I've used in javascript.

I dont know if it will be cached.


I also found a way to apend a javascript library in the widget. You could take a look at the simplechart widget in the appstore.