Search code examples
reactjscdngatsbyreact-helmet

CDN-script in Helmet does not always load properly


I am building a site using React + Gatsby and need to use Paper.js on the client side.

Currently I put the script into inside the render()


<Helmet>
<script src="https://cdnjs.cloudflare.com/ajax/libs/paper.js/0.12.2/paper-full.min.js" />
</Helmet>

However it is working when i reload (f5) but not when the user is directed to the page clicking a Gatsby-Link element (to="/path")

What could be my problem?


Solution

  • You can pass Helmet a script prop with an array of scripts to include:

    <Helmet
      script={[
        {
          "src": "https://cdnjs.cloudflare.com/ajax/libs/paper.js/0.12.2/paper-full.min.js", 
          "type": "text/javascript"
        }
      ]}
    >
    ...
    </Helmet>