Correct way to load other js libraries from form.js

Hello,

I need to edit an OoD app. I started from the jupyter one.
Now I need to load an additional javascript library in my form.js code.
What is the correct way to load it from a file in form.js?
It must be very basic but I couldn’t find more on the javascript development within OoD and I’m lost.

Thank you very much !

Hi thanks for the question, and welcome!

The only docs on this that I could find on this are here:
https://osc.github.io/ood-documentation/latest/tutorials/tutorials-interactive-apps/add-matlab/edit-form-js.html?highlight=form%20js

So you can add that form.js and place your code there to then use on the page.

An example that you might find interesting would be the bc_osc_codeserver app:

Hello, thank you for your reply. I’m not sure how this and the file picker have been done. I miss a bit the steps in between; I assumed that there was an easy way to load other js files from the form.js. I guess that I have to investigate more the file picker then. Thanks

You have 2 options here in 3.1

The first is you can build everything into 1 single javascript file. That’s how bc_js_filepicker works - it builds all the dependencies and so on into 1 single javascript file. There are a a lot of javascript packaging systems out there, that library uses wepack.

The other alternative is is to use HTML import maps.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap

You can pull the libraries you want from a CDN or similar so you don’t have to package them into 1 file, they can load on the client’s browser at runtime. You can pull the libraries off of a public CDN or copy the libraries to the OOD’s public folder and have your javascript file reference that relative URL.

Thank you very much, that’s very helpful!