Api

Nuxt Config

Last updated by Harlan Wilton in chore: lint.

registry

  • Type: ScriptRegistry

Global registry scripts to load.

See the Script Registry for more details.

partytown Experimental

  • Type: (keyof ScriptRegistry)[]
  • Default: []

Registry scripts to load via Partytown (web worker).

Listing a script here loads it with type="text/partytown" so Partytown can execute it in a web worker.

export default defineNuxtConfig({
  scripts: {
    partytown: ['googleAnalytics', 'plausible', 'fathom'],
    registry: {
      googleAnalytics: { id: 'G-XXXXX' },
      plausible: { domain: 'example.com' },
      fathom: { site: 'XXXXX' }
    }
  }
})
Requires you to install @nuxtjs/partytown. Nuxt automatically configures the forward array for supported registry scripts.

Supported Scripts

Scripts with auto-forwarding configured:

  • googleAnalytics, plausible, fathom, umami, matomo, segment
  • metaPixel, xPixel, tiktokPixel, snapchatPixel, redditPixel
  • cloudflareWebAnalytics

Limitations

Incompatible scripts - The following cannot work with Partytown due to DOM access requirements:
  • Tag managers: Google Tag Manager, Adobe Launch
  • Session replay: Hotjar, Clarity, FullStory, LogRocket
  • Chat widgets: Intercom, Crisp, Drift, HubSpot Chat
  • Video players: YouTube, Vimeo embeds
  • A/B testing: Optimizely, VWO, Google Optimize
General limitations:
  • Scripts cannot directly access or modify the DOM
  • document.cookie access requires additional Partytown configuration
  • Debugging is more complex (code runs in a web worker)
  • Some scripts may have timing differences compared to main thread execution
  • localStorage/sessionStorage access may require forwarding configuration

defaultScriptOptions

  • Type: NuxtUseScriptOptions
  • Default: { trigger: 'onNuxtReady' }

Default options for scripts. See the useScript() documentation for more details.

globals

  • Type: (NuxtUseScriptInput | [NuxtUseScriptInput, NuxtUseScriptOptions])[]
  • Default: []

Global scripts to load on all pages. This configuration applies to the useScript() composable.

See the Globals documentation for more details.

enabled

  • Type: boolean
  • Default: true

Disables the Nuxt Scripts module.

debug

  • Type: boolean
  • Default: false

Enable to see debug logs.

assets

  • Type: object
  • Default: { prefix: '/_scripts/', strategy: 'public' }

Controls how Nuxt bundles scripts for serving.

See the Bundling documentation for more details.

assets.fallbackOnSrcOnBundleFail

  • Type: boolean
  • Default: false

Fallback to the remote src URL when bundle fails when enabled. By default, the bundling process stops if the third-party script can't be downloaded.

assets.fetchOptions

  • Type: object
  • Default: { retry: 3, retryDelay: 2000, timeout: 15_000 }

Options to pass to the fetch function when downloading scripts.

assets.integrity

  • Type: boolean | 'sha256' | 'sha384' | 'sha512'
  • Default: false

Enable automatic Subresource Integrity (SRI) hash generation for bundled scripts. When enabled, calculates a cryptographic hash of each bundled script and injects the integrity attribute along with crossorigin="anonymous".

See the Bundling - Subresource Integrity documentation for more details.