---
title: "Global Scripts · Nuxt Scripts"
description: "Load global third-party scripts and optimize them for your Nuxt app."
canonical_url: "https://scripts.nuxt.com/docs/v0/guides/global"
meta:
  "og:description": "Load global third-party scripts and optimize them for your Nuxt app."
  "og:image": "https://scripts.nuxt.com/_og/d/c_Docs%2Ctitle_Global%2BScripts%2Cdescription_Load%2Bglobal%2Bthird-party%2Bscripts%2Band%2Boptimize%2Bthem%2Bfor%2Byour%2BNuxt%2Bapp.%2Cheadline_Guides%2Cp_Ii9kb2NzL3YwL2d1aWRlcy9nbG9iYWwi%2Cs_HjUOl7EQ0vCs5VTN.png"
  "og:image:height": "600"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "Global Scripts · Nuxt Scripts"
  "twitter:image": "https://scripts.nuxt.com/_og/d/c_Docs%2Ctitle_Global%2BScripts%2Cdescription_Load%2Bglobal%2Bthird-party%2Bscripts%2Band%2Boptimize%2Bthem%2Bfor%2Byour%2BNuxt%2Bapp.%2Cheadline_Guides%2Cp_Ii9kb2NzL3YwL2d1aWRlcy9nbG9iYWwi%2Cs_HjUOl7EQ0vCs5VTN.png"
---

> Index of every page on this site: [llms.txt](https://scripts.nuxt.com/llms.txt)

**Guides**

# **Global Scripts**

[Copy for LLMs](https://scripts.nuxt.com/docs/v0/guides/global.md)

## Background

While the `**app.head**` method in Nuxt Config allows for loading global scripts, it can be cumbersome and requires manual optimization.

```ts
export default defineNuxtConfig({
  head: {
    script: [ { src: 'https://analytics.com/tracker.js',  async: true } ]
  }
})
```

A simpler method is now available: directly input the script URL into `**scripts.globals**`. You can also include optional settings to tailor the script loading process with specific optimizations in mind.

You may consider using global scripts when:

- The script isn't a supported [**Registry Script**](https://scripts.nuxt.com/docs/v0/api/use-script#registry-script).
- You don't care about interacting with the API provided by the third-party script (e.g. you don't need to use `**gtag**` from Google Analytics).
- You are interacting with the API provided by the third-party script, but you don't care about type safety.

Otherwise, it's recommended to use [**useScript**](https://scripts.nuxt.com/docs/v0/api/use-script) to load scripts in a safer way.

## Usage

The `**globals**` key supports strings, objects and arrays.

**Example: Load a script using just the src**

```ts
export default defineNuxtConfig({
  scripts: {
    globals: {
      myScript: 'https://analytics.com/tracker.js',
    }
  }
})
```

**Example: Load a script while providing extra script attributes**

```ts
export default defineNuxtConfig({
  scripts: {
    globals: {
      myScript: {
        src: 'https://example.com/script.js',
        integrity: 'sha256-abc123',
      }
    }
  }
})
```

You can optionally provide the script as an array which allows you to provide [**Script Options**](https://scripts.nuxt.com/docs/v0/api/use-script#NuxtUseScriptOptions).

```ts
export default defineNuxtConfig({
  scripts: {
    globals: {
      myScript: [
        { src: 'https://example.com/script.js' },
        // load the script as part of the hydration process instead of on idle
        { trigger: 'client' }
      ]
    }
  }
})
```

### Accessing a global script

All Nuxt Scripts are registered on the `**$scripts**` Nuxt App property.

For scripts registered through nuxt.config, type autocompletion is available.

```vue
<script setup lang="ts">
const { $scripts } = useNuxtApp()
$scripts.myScript // { $script, instance }
</script>
```

## How it Works

The `**globals**` configuration will be used to create a virtual Nuxt plugin that loads in the script using the `**useScript**` composable.

As `**useScript**` is being used under the hood, it's important to understand the defaults and behavior of the [**useScript**](https://scripts.nuxt.com/docs/v0/api/use-script) composable..

```ts
export default defineNuxtConfig({
  scripts: {
    globals: {
      tracker: 'https://analytics.com/tracker.js',
    }
  }
})
```

[Edit this page](https://github.com/nuxt/scripts/edit/0.x/docs/content/1.guides/4.global.md)

[Markdown For LLMs](https://scripts.nuxt.com/docs/v0/guides/global.md)

[**Script Event Page** Learn how to send page events to your analytics provider.](https://scripts.nuxt.com/docs/v0/guides/page-events) [**Facade Components** Facade Components are fake UI elements that get replaced once a third-party script loads.](https://scripts.nuxt.com/docs/v0/guides/facade-components)

**On this page **

- [Background](#background)
- [Usage](#usage)
- [How it Works](#how-it-works)

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://scripts.nuxt.com/#website","@type":"WebSite","description":"Nuxt Scripts lets you load third-party scripts with better performance, privacy, security and DX. It includes many popular third-parties out of the box.","name":"Nuxt Scripts","url":"https://scripts.nuxt.com/","publisher":{"@id":"https://scripts.nuxt.com/#identity"}},{"@id":"https://scripts.nuxt.com/docs/v0/guides/global#webpage","@type":"WebPage","description":"Load global third-party scripts and optimize them for your Nuxt app.","name":"Global Scripts","url":"https://scripts.nuxt.com/docs/v0/guides/global","breadcrumb":{"@id":"https://scripts.nuxt.com/docs/v0/guides/global#breadcrumb"},"isPartOf":{"@id":"https://scripts.nuxt.com/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://scripts.nuxt.com/docs/v0/guides/global"]}],"primaryImageOfPage":{"@id":"https://scripts.nuxt.com/#logo"}},{"@id":"https://scripts.nuxt.com/#identity","@type":"Organization","name":"Nuxt Scripts","url":"https://scripts.nuxt.com","logo":{"@id":"https://scripts.nuxt.com/#logo"}},{"@id":"https://scripts.nuxt.com/docs/v0/guides/global#breadcrumb","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","name":"Nuxt Scripts","item":"https://scripts.nuxt.com/","position":1},{"@type":"ListItem","name":"Documentation","item":"https://scripts.nuxt.com/docs","position":2},{"@type":"ListItem","name":"V0","item":"https://scripts.nuxt.com/docs/v0","position":3},{"@type":"ListItem","name":"Guides","item":"https://scripts.nuxt.com/docs/v0/guides","position":4},{"@type":"ListItem","name":"Global Scripts","item":"https://scripts.nuxt.com/docs/v0/guides/global","position":5}]},{"@id":"https://scripts.nuxt.com/#logo","@type":"ImageObject","caption":"Nuxt Scripts","contentUrl":"https://scripts.nuxt.com/logo.svg","inLanguage":"en","url":"https://scripts.nuxt.com/logo.svg"}]}
```

## Sitemap

See the full [sitemap](https://scripts.nuxt.com/sitemap.md) for all pages.
