Import Javascript file from Assets

Ok, it’s actually documented here:

https://anvil.works/docs/client/themes-and-styling

Relative path would be _/theme/filename.js

This works in the component, but my guess is it will not work when the component is imported into another app (because the base path of that app will not point to correct location).

Not sure there’s an ideal solution here. I could use the absolute path of the component app, but that’s a little scary, and may create XSS issues when my main app is served off a custom domain.

Another thought would be to create the initialization function in Native Libraries, which will be run in the header, and then call it if from Python when I set up the form.

Any guidance from people doing this would be appreciated.

John

4 Likes