stijn.aerts
stijn.aerts

Reputation: 6206

including external javascript in Gatsby using Helmet

I have this code in the index.js of layout folder:

<StaticQuery
    query={graphql`
      query SiteTitleQuery {
        site {
          siteMetadata {
            title
          }
        }
      }
    `}
    render={data => (
      <>
        <Helmet
          title={data.site.siteMetadata.title}
          meta={[
            {name: 'description', content: 'Sample'},
            {name: 'keywords', content: 'sample, something'},
          ]}
          script={[
            {"src": "http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js", "type": "text/javascript"}
          ]}
        >
          <html lang="en" />

        </Helmet>
        <Header siteTitle={data.site.siteMetadata.title} />
        <div>
          {children}
        </div>
        <Footer />
      </>
    )}
  />

However the Bootstrap.js file is not included in the project... I tried various syntax things and also restarted the project, nothing works so far.

Upvotes: 4

Views: 1420

Answers (1)

Saša Šijak
Saša Šijak

Reputation: 9291

Helmet supports all valid head tags like title, base, meta, link, noscript, style, including script tag. So you can do it like this :

<Helmet>
  <script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js" type="text/javascript" />
</Helmet>

Upvotes: 2

Related Questions