Adding script tag embed to Gatsby component | Double Marvellous
Back to Blog
Development Oct 14, 2024 4 min read

Adding script tag embed to Gatsby component

Adding script tag embed to Gatsby component

This one broke my heart for a could of hours, which annoyed me as it really shouldn’t have. I like working with Gatsby but the clashing versions and updates really drags the progress down. This project I hadn’t opened in a few months and it basically started crying when I ran it due to the Gatsby version being a bit old.

So what worked?

Even though it’s going to be - or has already been - deprecated (sigh, of course) the Helmet api worked for me here. There are new APIs introduced to replace this but I ended up fighting with them so went back to Helmet. Time management is also a factor! This job should have taken less than five minutes…

So import Helmet to your component.

Then inside this Helment tag, use the script tag as normal, BUT wrap your js in curly braces like a template literal. Like so:

<script type='text/javascript' id="insert-bsport-widget-cdn">{`someFunction(){alert('cowabunga');}`}</script>

Double Marvellous

AI Chatbot

Double Marvellous.