I need to add a script tag to my site but I cannot get it to work.
The instructions say to add to the head tag of the site but I am using Meteor + React and there are no html pages are head tag to add it too.
In the meteor tutorial it says
Meteor parses all of the HTML files in your app folder and identifies three top-level tags: <head>, <body>, and <template>.
Everything inside any <head> tags is added to the head section of the HTML sent to the client, and everything inside <body> tags is added to the body section, just like in a regular HTML file.
So I added a html file in the client directory and added the script tag inside head tag and it does not work. Meteor does not pickup any changes to html files in my project. It is as if the html file does not exist.
I tried using jquery getScript to add the script once the main layout component did mount but that did not work either.
I had the same problem a while back. I was able to load it in componentDidMount in a high level Component.
componentDidMount () {
function loadScript() {
var script= document.createElement('script');
script.type= 'text/javascript';
script.src= 'yourURLhere.js';
script.async = true;
document.body.appendChild(script);
}
loadScript();
}
You can also use react-helmet.
Sample code:
<Helmet>
<meta charSet="utf-8" />
<title>My Title</title>
</Helmet>
Results in:
<head>
<meta charSet="utf-8" />
<title>My Title</title>
</head>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With