Author -  Sai gowtham

How to add the script tag to a head in Nuxt

In this tutorial, we are going to learn about how to add the external script tags to a head, body in the nuxt app.

Adding a script to head

  1. Open the nuxt app in your favorite code editor.

  2. Navigate to the nuxt.config.js file.

  3. Now, add the script tag like this inside your head object script array.

nuxt.config.js
export default {
  head: {
    script: [
      {        src: "https://code.jquery.com/jquery-3.5.1.min.js",      },    ],
  }
  // other config goes here
}

It adds the jquery script tag to all pages in your nuxt app.

If you want to add a script tag before closing the </body> instead of <head> tag, you can do it by adding a body: true.

nuxt.config.js
export default {
  head: {
    script: [
      {
        src: "https://code.jquery.com/jquery-3.5.1.min.js",
        body: true,      },
    ],
  }
  // other config goes here
}

You can also add async, cross-origin attributes to a script tag like this.

nuxt.config.js
export default {
  head: {
    script: [
      {
        src: "https://code.jquery.com/jquery-3.5.1.min.js",
        async: true,        crossorigin: "anonymous"      },
    ],
  }
  // other config goes here
}

output:

<script data-n-head="ssr" src="https://code.jquery.com/jquery-3.5.1.min.js"
crossorigin="anonymous" async=""></script>

Adding script tag to particular page

You can also add a script tag to the particular page in your nuxt app like this.

About.vue
<template>
  <h1>This is about page</h1>
</template>

<script>
  export default {
    head() {
      return {
        script: [
          {
            src: 'https://code.jquery.com/jquery-3.5.1.min.js'
          }
        ],
      }
    }
  }
</script>

<style scoped>
</style>

Css Tutorials & Demos

How rotate an image continuously in CSS

In this demo, we are going to learn about how to rotate an image continuously using the css animations.

How to create a Instagram login Page

In this demo, i will show you how to create a instagram login page using html and css.

How to create a pulse animation in CSS

In this demo, i will show you how to create a pulse animation using css.

Creating a snowfall animation using css and JavaScript

In this demo, i will show you how to create a snow fall animation using css and JavaScript.

Top Udemy Courses

JavaScript - The Complete Guide 2023 (Beginner + Advanced)
JavaScript - The Complete Guide 2023 (Beginner + Advanced)
116,648 students enrolled
52 hours of video content
$14.99 FROM UDEMY
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
631,582 students enrolled
49 hours of video content
$24.99 FROM UDEMY
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
203,937 students enrolled
31.5 hours of video content
$14.99 FROM UDEMY