Mads Hjorth
Mads Hjorth

Reputation: 447

Adding an external script to Nuxt

I have a script from a third party, that I need implemented on my Nuxt site in the Header. What would be the best way to insert a script such as this?

<script id="sleeknoteScript" type="text/javascript">
(function (){
    var sleeknoteScriptTag=document.createElement("script");
    sleeknoteScriptTag.type="text/javascript";
    sleeknoteScriptTag.charset="utf-8";
    sleeknoteScriptTag.src=("//sleeknotecustomerscripts.sleeknote.com/00000.js");
    var s=document.getElementById("sleeknoteScript");
    s.parentNode.insertBefore(sleeknoteScriptTag, s);
})(); </script>
<!-- End of Sleeknote signup and lead generation tool - www.sleeknote.com -->

Usually I would put scripts in Nuxt.config like this.

    script: [
      { src: 'https://unpkg.com/@lottiefiles/[email protected]/dist/lottie-player.js' },
  ]

But this one I don't know.

Upvotes: 0

Views: 478

Answers (1)

ajobi
ajobi

Reputation: 3116

You can do it in the same way, just place the script into a javascript file and use the path to that file as a script's src property value in the nuxt.config.js:

script: [
  { src: '/scripts/myScript.js' },
]

The myScript.js would be placed in static/scripts/myScript.js in this case

Upvotes: 4

Related Questions