loading 3rd party scripts inside the page #633
-
hey! My question is quite specific, and I could not find something in forums. I'm trying to integrate hubspot forms to a page. I'm working with Astro, so what I end up doing was adding this to a page.
if the page is loaded initially it works, but the moment I'm comming from a different route it does not work. Any help is welcome |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
You'll find the scripts plugin useful here. It will re-run script tags found in the head and/or body. |
Beta Was this translation helpful? Give feedback.
-
I think the way the scripts plugin re-runs scripts is asynchronous, so your second script tag will be executed before the first one is fully loaded. You could try a script loader like load-script-once and then execute the second part with <script>
loadScriptOnce('//js.hsforms.net/forms/embed/v2.js').then(() => {
hbspt.forms.create({})
})
</script> |
Beta Was this translation helpful? Give feedback.
I think the way the scripts plugin re-runs scripts is asynchronous, so your second script tag will be executed before the first one is fully loaded. You could try a script loader like load-script-once and then execute the second part with
forms.create
in the callback.