---
title: "Key Concepts · Nuxt Scripts"
description: "Learn about the key concepts of Nuxt Scripts."
canonical_url: "https://scripts.nuxt.com/docs/guides/key-concepts"
meta:
  "og:description": "Learn about the key concepts of Nuxt Scripts."
  "og:image": "https://scripts.nuxt.com/_og/s/o_35d5174716a29370.png"
  "og:image:height": "600"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "Key Concepts · Nuxt Scripts"
  "twitter:image": "https://scripts.nuxt.com/_og/s/o_35d5174716a29370.png"
---

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

**Guides**

# **Key Concepts**

[Copy for LLMs](https://scripts.nuxt.com/docs/guides/key-concepts.md)

[`**useScript()**`](https://scripts.nuxt.com/docs/api/use-script) is the base API. Registry and global scripts build on it for common loading patterns:

1. [**Registry Scripts**](https://scripts.nuxt.com/docs/guides/registry-scripts): Preconfigured third-party scripts that load through Nuxt config, composables, and components.
2. [**Global Scripts**](https://scripts.nuxt.com/docs/guides/global): Scripts loaded through your Nuxt config file.

## Unhead abstraction

Nuxt Scripts wraps Unhead's [`**useScript()**`](https://unhead.unjs.io/docs/nuxt/head/api/composables/use-script), which builds on [`**useHead()**`](https://unhead.unjs.io/docs/nuxt/head/api/composables/use-head). Script attributes supported by `**useHead**` are therefore available through Nuxt Scripts too.

## Script singleton

Nuxt Scripts deduplicates calls with the same `**src**` (or `**key**`) because scripts load globally and all components share them.

The first call initializes the script. Later calls with the same identity return that instance.

Wrap a repeated call in a composable so every component uses the same configuration:

useMyScript.ts

```ts
export function useMyScript() {
  return useScript({
    src: 'https://example.com/script.js',
  })
}
```

## Default behavior

By default, Nuxt Scripts leaves script tags out of the SSR response and loads them on the client with the `**onNuxtReady**` trigger. This keeps third-party code out of hydration.

You can change this behavior by modifying the [**defaultScriptOptions**](https://scripts.nuxt.com/docs/api/nuxt-config#defaultscriptoptions).

Nuxt Scripts also applies several privacy and performance defaults to cross-origin script elements:

- `**crossorigin="anonymous"**`: Prevents the script request from sending cross-origin credentials, including cookies.
- `**referrerpolicy="no-referrer"**`: Prevents sharing the page URL with third-party servers.

When you enable warmup, `**<link>**` hints use `**fetchpriority="low"**` to avoid competing with critical resources.

## Understanding proxied functions

[`**useScript()**`](https://scripts.nuxt.com/docs/api/use-script) can return functions before the browser has loaded their script:

```ts
const { proxy } = useScript('/script.js', {
  use: () => ({ gtag: (window as any).gtag }),
})
proxy.gtag('event', 'page_view')
```

The proxy queues the `**gtag**` call and replays it after the script loads. If the script never loads, the call never runs.

This is useful when:

- the same code runs during SSR;
- an ad blocker may prevent the script from loading; or
- your application may call the API before the request finishes.

Proxy calls have two tradeoffs:

- Proxy calls return `**undefined**`. Use `**load()**` or `**onLoaded()**` when you need a function's return value.
- A queued call can be harder to trace because it runs later, after the script becomes available.

Await the load when you need the script API directly:

```ts
const { onLoaded } = useScript('/script.js', {
  use: () => ({ gtag: (window as any).gtag }),
})
// use the script instance directly, not proxied
onLoaded(({ gtag }) => {
  gtag('event', 'page_view')
})
```

[Edit this page](https://github.com/nuxt/scripts/edit/main/docs/content/1.guides/0.key-concepts.md)

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

[**Contributing** Set up the Nuxt Scripts repository for local development.](https://scripts.nuxt.com/docs/getting-started/contributing) [**Registry Scripts** Configure, reuse, and extend typed integrations from the Nuxt Scripts registry.](https://scripts.nuxt.com/docs/guides/registry-scripts)

**On this page **

- [Unhead abstraction](#unhead-abstraction)
- [Script singleton](#script-singleton)
- [Default behavior](#default-behavior)
- [Understanding proxied functions](#understanding-proxied-functions)

```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/key-concepts#webpage","@type":"WebPage","description":"Learn about the key concepts of Nuxt Scripts.","name":"Key Concepts","url":"https://scripts.nuxt.com/docs/guides/key-concepts","breadcrumb":{"@id":"https://scripts.nuxt.com/docs/guides/key-concepts#breadcrumb"},"isPartOf":{"@id":"https://scripts.nuxt.com/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://scripts.nuxt.com/docs/guides/key-concepts"]}],"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/key-concepts#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":"Key Concepts","item":"https://scripts.nuxt.com/docs/guides/key-concepts","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.
