DEV Community

Add Custom JavaScript to a Gatsby Site

Steven Mercatante on October 14, 2019

This post was originally published at stevemerc.com I recently found myself needing to add some custom JavaScript to the head of a Gatsby pro...
Collapse
 
itmayziii profile image
Tommy May III

Please try and avoid ejecting html.js unless you have to. The out of the box APIs could accomplish adding a script to the head
gatsbyjs.org/docs/ssr-apis/#onRend...

Collapse
 
mercatante profile image
Steven Mercatante

Hi Tommy, thanks for mentioning onRenderBody. You're right that it can be used to render custom scripts in the head, but I still think there's value in knowing how to manually tweak html.js for fine-grained control. I'll update this article to include an example using onRenderBody, though.