---
title: "Global Scripts · Nuxt Scripts"
description: "Configure global scripts with triggers, warmup, typed access, and runtime URL overrides."
canonical_url: "https://scripts.nuxt.com/docs/guides/global"
meta:
  "og:description": "Configure global scripts with triggers, warmup, typed access, and runtime URL overrides."
  "og:image": "https://scripts.nuxt.com/_og/s/o_efa9926267711d15.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/s/o_efa9926267711d15.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/guides/global.md)

## Background

Nuxt's `**app.head**` can load a global script:

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

`**scripts.globals**` routes the same script through Nuxt Scripts, including its triggers and warmup behavior.

Use a global script when:

- The script isn't a supported [**Registry Script**](https://scripts.nuxt.com/docs/guides/registry-scripts).
- You do not call the third-party API, such as `**gtag**`.
- You call the API but do not need it typed.

Use a registry composable or [`**useScript()**`](https://scripts.nuxt.com/docs/api/use-script) when you need a typed API.

## Usage

The `**globals**` key supports strings, objects, and two-item tuples.

### URL string

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

### Script attributes

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

### Script options

Use a two-item tuple to include [**Script Options**](https://scripts.nuxt.com/docs/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' }
      ]
    }
  }
})
```

Keep `**trigger**` in the tuple's second item. If it is placed beside `**src**` in the input object, the current generated plugin passes it as script input rather than as a `**useScript**` option, so the global still inherits the module's default trigger.

### Overriding the script per deployment

Override globals through [**Nuxt's public runtime config**](https://nuxt.com/docs/guide/going-further/runtime-config) with `**NUXT_PUBLIC_SCRIPTS_GLOBALS_***` environment variables. One build can then use different Trusted Shops, Awin, or GTM values across deployments.

The env var path mirrors the global's key in `**SCREAMING_SNAKE_CASE**` (camelCase boundaries become underscores):

nuxt.config.ts

```ts
export default defineNuxtConfig({
  scripts: {
    globals: {
      trustedShops: {
        src: 'https://widgets.trustedshops.com/build-default.js',
      },
    },
  },
})
```

.env per deployment

```bash
# Override the src for this deployment only:
NUXT_PUBLIC_SCRIPTS_GLOBALS_TRUSTED_SHOPS_SRC=https://widgets.trustedshops.com/X1234.js
```

Object fields such as `**src**`, `**integrity**`, `**crossorigin**`, and `**referrerpolicy**` can be overridden this way. The environment value replaces the build-time default at runtime via `**runtimeConfig.public.scriptsGlobals**`.

#### **Disabling a global per deployment**

A deployment can also skip a global without rebuilding. Use an empty `**src**` in an environment variable. A runtime hook or typed runtime-config value can instead set `**enabled**` to the boolean `**false**`:

.env per deployment

```bash
# Drop this integration for this instance only:
NUXT_PUBLIC_SCRIPTS_GLOBALS_AWIN_SRC=
```

A disabled global resolves to `**undefined**` on `**$scripts**`, so guard access (`**$scripts.awin?.**`) if a script may be turned off per instance.

#### **Computing globals at runtime**

Use the [`**scripts:globals**`](https://scripts.nuxt.com/docs/api/nuxt-app-hooks#scriptsglobals) runtime hook when `**src**` depends on runtime config or a deployment must remove an entry conditionally. The hook receives the resolved inputs immediately before registration. Rewrite or delete declared entries there; their `**$scripts**` types remain available.

**Not overridable at runtime:**

- `**scriptOptions**` (the second tuple slot, for example `**trigger**` or `**warmupStrategy**`) stay baked in at build.
- Asset bundling: the bundle transformer can't statically read `**src**` through the runtime-config wrapper, so it skips globals that are environment-overridable. They load directly from their CDN at runtime. If you need bundling, use `**useScript()**` with a static `**src**` instead.

Typos in environment-variable keys produce warnings with suggestions. For example, `**NUXT_PUBLIC_SCRIPTS_GLOBALS_TRUSTED_SHOP_SRC**` suggests `**trustedShops**`.

### Accessing a global script

Nuxt Scripts registers globals on the Nuxt app's typed `**$scripts**` property:

```vue
<script setup lang="ts">
const { $scripts } = useNuxtApp()
$scripts.myScript // UseScriptContext<any> | undefined
</script>
```

## Generated plugin

The module turns `**scripts.globals**` into a virtual Nuxt plugin. That plugin calls [`**useScript()**`](https://scripts.nuxt.com/docs/api/use-script), so globals share its defaults and singleton behavior.

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

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

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

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

**On this page **

- [Background](#background)
- [Usage](#usage)
- [Generated plugin](#generated-plugin)

```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/guides/global#webpage","@type":"WebPage","description":"Configure global scripts with triggers, warmup, typed access, and runtime URL overrides.","name":"Global Scripts","url":"https://scripts.nuxt.com/docs/guides/global","breadcrumb":{"@id":"https://scripts.nuxt.com/docs/guides/global#breadcrumb"},"isPartOf":{"@id":"https://scripts.nuxt.com/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://scripts.nuxt.com/docs/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/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":"Guides","item":"https://scripts.nuxt.com/docs/guides","position":3},{"@type":"ListItem","name":"Global Scripts","item":"https://scripts.nuxt.com/docs/guides/global","position":4}]},{"@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.
