I was given the task to develop sliders/pop-ups for customers of the company I work for. This works a bit like chatbots (ie. Intercom). The user sees a small bubble on the bottom-right corner, clicks on it and it shows some information from our (Rails) app.
What’s the best way to create a javascript code to share with those clients? Should I add my code to a public js file and send those clients a script targeting my app? (like the example below?)
<script src='https://www.myapp.com/script.js'></script>
I’ve tried to do so, but it looks like the script doesn’t link to my CSS files, so styles are broken. So I am not sure if it’s the best way to go.
Advertisement
Answer
You’re using the right approach.
To fix your missing CSS you could adjust your script to add the required CSS references to the head
of the page.
let externalCssLink = document.createElement('link') externalCssLink.rel = 'stylesheet' externalCssLink.href = 'https://some-external-domain.com/some-css.css' document.head.appendChild(externalCssLink)