I’d recommend using HasShortcode in the head so the script is only loaded if the post has a shortcode.
Also, use {{/* and */}} to stop Hugo from trying to render a template tag so you can include it in a code snippet.