How to make a <script> with dynamic "src" parameter?

Hi everyone!

I have a live chat script on a website, similar to Intercom.
Currenly it is simple tag, like <script src="//" async></script>

Now I want to use different scripts in different situations (for example, depending on the user’s selected language).
So it has to be dynamic data binding, like <script dmx-bind:src="" async></script>

But I quickly recognized that dmx-bind:src doesn’t work here. I read some forum threads, including this, so I’ve got a better understanding, why exactly dmx-bind:src doesn’t work.
If I understand, there is some solution to this, but I can’t find a clear instruction.

Seems like I have to prepare a script and run it via “Run JavaScript” step in “Page flow” or via Static Event after page or data loaded.
But specific steps are a bit unclear for me. Because of the lack of JavaScript knowledge and how it works in Wappler.

Can someone please give me a detailed instructions, how to solve this?

This is a simpler example I could find on how to build your JS function which would inject the script tag.
There are other sample codes on the page, which you can try as well.

Once you have created this function on page or in your custom JS file, call that function in page flow.
Hope this helps.

1 Like

Thank you very much, @sid! Seems like indeed there are plenty of options. I will investigate and try, then.

If the dynamic data is coming from the database and therefore from Server Connect you can always use EJS templating to SSR the script src attribute.


That’s an interesting idea, I’m not even thought about it. I’ll try it, maybe it gonna work. Thank you!

It totally worked!
Thank you very much again for great advice! :beers:

1 Like