External Javascript Library

Hi! I need some help figuring out how to reference my external Javascript. I would like to create my own custom Javascript library, and I wrote some stuff up, put it in a test.js file, made it publicly accessible, and used the 3 dots to add my script to a very simple app.

The only thing in my script is a variable definition, and the only thing in my test app is a javascript query that references my variable. But, the variable is red, not green, as if Retool can't resolve the reference.

I read the following link, but couldn't make heads or tails out of what I need to do. It seems the others are using public domain libraries, and I want to use my own stuff. So, I can't tell if a "library" is something extra or if a regular old Javascript file will work.

Oh, BTW, I had been using the Organization-level Pre-loaded Javascript, but as I continued developing, the tiny editor became more and more of a problem. Also, if a single syntax error was made, it seemed to make the entire script inaccessible, and so it will be easier for me to keep my stuff clean if I can develop my own external scripts.

Ok. So, I spent a very long time trying to figure out what the format for the Javascript library was supposed to look like. Never could figure it out.

But, I did figure out how I could solve my real problem. My real problem is having two dashboards that need to share code. I tried putting it the Preloaded Javascript library, which would have worked, but it became increasingly difficult to maintain as it grew. A single typo seemed to break the whole thing, with no debug output I could find to help drill down where the problem was. My only solution was to comment out large portions and gradually uncomment parts until it broke. Then, I knew what section to look at. Too time consuming.

Libraries, I just could not get working.

But, modules. That I could do. I didn't think of it at first, because I thought of a module as being a display piece, as in it would be the header part of the app or something, but I really just needed inputs and outputs. In the end, I ended up having the module be a sidebar, that way I could enforce the selection options that were being provided as inputs, so I'm not sure if it would work for pure code encapsulation without the visual components. But, for me, it provides a way to write code once and use it twice, and that's what I need.

Hey, I have been trying to do the same, but without any luck, did you manage to figure out how to create your own custom external library? Maybe someone from Retool could help clarify? Can we create our own custom library with code specific to our business models and logic? or we can only load libraries from here: Libraries - cdnjs - The #1 free and open source CDN built to make life easier for developers

OK, I believe I figured out, Retool might be checking for specific urls to allow libraries, we don't seem to be able to load custom libraries. I would love if somenone from Retool team could confirm this, but this is most likely what is happening.

The main guideline around imported libraries is to make sure they're UMD builds. They don't have to be from a particular URL so you should be able to host your own!

The dev team is looking at improving the experience of integrating code with Retool more generally as well. The amount of work you had to do here to get modular code is way more than ideal @nl-setech :grimacing: Hopefully we can make the experience smoother for both of you!

It could be worth checking your browser's dev tools for any errors @sebap, that might give some insight as to why the custom library isn't working.

Hey @Kabirdas , thanks for your reply, but I did a little experiment. I copied the content of the Pusher library, one that I found works if imported, and pasted it in a file that i am hosting myself, and the library does not recognize the Pusher object. But if imported from the original source, it works just fine. There must be some validation that is happening internally, it would be great to have this documented.

Hey @Kabirdas, thanks for the tip, looked into the dev console and there was a CORS issues, I think i could try few more things here :smiley:

Awesome! If you try and still run into issues let me know! :slightly_smiling_face: