Next.js: Dependency Footer Scripts

Created on 13 Feb 2017  Â·  6Comments  Â·  Source: vercel/next.js

Question:

Originally I was considering to use <Head> to load a polyfill if a specific component configured in a specific way.

Is there a way to say to inject a script to be included with the <NextScript /> block from within another component. The same way that we include a script within the head.

An example -

I built a image component that can also be a responsive image using srcset and sizes. I want to include the picturefill.min.js library if either of these attributes are not undefined.

Most helpful comment

@arunoda - sorry i just saw this very late. If you have time, would you be able to link the solution you were trying to share. The tiny google url apparently timed out.

All 6 comments

If you are looking for this, that's possible:

export default class extends Document {
  render() {
    return (
      <html>
        <Head />
        <body>
          <Main />
          <NextScript />
          <script src="your location" />
        </body>
      </html>
    );
  }
}

No. I mean by including a script tag in a component and having next inject it below next script.

The layout or document could be used for multiple pages, so I only want the script attached if the component using that script is rendered.

On Feb 13, 2017, 8:55 PM -0600, Arunoda Susiripala notifications@github.com, wrote:
>

If you are looking for this, that's possible:

export default class extends Document { render() { return (

Related issues

flybayer picture flybayer  Â·  3Comments

formula349 picture formula349  Â·  3Comments

rauchg picture rauchg  Â·  3Comments

timneutkens picture timneutkens  Â·  3Comments

jesselee34 picture jesselee34  Â·  3Comments