#Script tags are not loaded.
1 messages · Page 1 of 1 (latest)
Why can't you render the script tag as JSX?
I wrote the script tag directly, but nothing was displayed. I thought this might be because Remix is rendered on the server side and client-side scripts are not executed, so I decided to execute them on the client side using useEffect.
Is this understanding wrong?
Yes, remix itself renders both <script dangerouslySetInnerHTML={{ __html: "//the script" }} /> tags and <script src="/some-external-script.js" /> tags.
You are free to also render these at any point in your route hierarchy. I'd recommend keeping them in the root if possible below your <Scripts /> component.
Rendering a script does not cause it to execute on the server, it just adds it to the HTML delivered to the browser.
If you do useEffect() stuff, you have delayed the loading of that script until:
- Document if fully delivered
- React hydrates
- useEffect finally fires.
On a slow device this can be upwards of 2-3 seconds.
I wish Discord let you bookmark comments. Good stuff jacob!
Thank you, jacob. I think my approach with useEffect is correct because this time I want to execute the scripts on the client side as well as render them.
However, the problem this time is that I can't execute more than one script...