I want to know how to add external javascript file to gatsby, where should i put these tag in which file ? And also how to import the file properly to the DOM.
Thanks
You can add this part of code in you gatsby-ssr.js, this add code in your balise .
export const onRenderBody = ({ setHeadComponents }) => {
  setHeadComponents([
    <link
      rel="stylesheet"
      href="/style.css"
    />
  ])
}
You Have the same for the body
export const onRenderBody = ({ setHeadComponents, setPostBodyComponents }) => {
      setHeadComponents([
        <link
          rel="stylesheet"
          href="/style.css"
        />
      ]),
setPostBodyComponents([
       <script></script>,
      ]),
    }
                        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