Over a year ago I set out to build a module that would give Nuxt developers the best possible experience for managing third-party scripts - without sacrificing performance or their users' privacy.
Today I'm excited to announce that Nuxt Scripts has reached stable with v1.
In this post I'll cover what Nuxt Scripts does, the highlights of this release and what's next.
Third-party scripts are everywhere - analytics, ads, chat widgets, social embeds. They're also one of the biggest threats to your site's performance and your users' privacy:
Nuxt Scripts was built to solve all three.
To consider Nuxt Scripts stable I wanted to make sure it covered the most common use cases for third-party scripts while pushing the boundaries of what's possible with privacy and performance.
As of today, the module supports 30+ registry scripts, first-party proxying, web worker offloading, SSR social embeds and automatic SRI hashes - with a full suite of tests to avoid regressions.
Here are the highlights.
Third-party scripts expose data that can be used for fingerprinting users across sites. Ad blockers rightfully block these for privacy reasons.
First-party mode routes all script traffic through your own domain.
export default defineNuxtConfig({
scripts: {
firstParty: true,
registry: {
googleAnalytics: { id: 'G-XXXXXX' },
metaPixel: { id: '123456' },
}
}
})
What happens:
/_scripts/c/ga)Supported: Google Analytics, GTM, Meta Pixel, TikTok, Segment, Clarity, Hotjar, X/Twitter, Snapchat, Reddit.
Load third-party scripts off the main thread using Partytown. Scripts run in a web worker, freeing the main thread for your app.
export default defineNuxtConfig({
modules: ['@nuxtjs/partytown', '@nuxt/scripts'],
scripts: {
partytown: ['plausible', 'fathom', 'umami'],
registry: {
plausible: { domain: 'example.com' },
fathom: { site: 'XXXXX' }
}
}
// Forward array auto-configured — no manual setup needed!
})
Auto-forwarding is supported for all major analytics and pixel scripts including Google Analytics, Plausible, Fathom, Umami, Matomo, Segment, and more.
Third-party embed scripts (Twitter widgets, Instagram embeds) hurt performance and leak user data. Following the Cloudflare Zaraz approach, we now fetch embed data server-side and proxy all assets through your domain.
<ScriptXEmbed tweet-id="1754336034228171055">
<template #default="{ userName, text, likesFormatted, photos }">
<!-- Full styling control via scoped slots -->
</template>
</ScriptXEmbed>
Privacy benefits:
Scripts now expose a .reload() method for re-executing DOM-scanning scripts after SPA navigation.
const script = useScript('/third-party.js')
await script.reload()
Bundled scripts can automatically generate Subresource Integrity hashes, protecting against tampered scripts.
export default defineNuxtConfig({
scripts: {
assets: {
integrity: 'sha384'
}
}
})
ratio propBuilt-in support for Google's Consent Mode v2, making GDPR compliance straightforward.
export default defineNuxtConfig({
scripts: {
registry: {
googleTagManager: {
id: 'GTM-XXXX',
defaultConsent: {
ad_storage: 'denied',
analytics_storage: 'denied'
}
}
}
}
})
This release includes a small number of breaking changes, primarily around the YouTube Player component.
ratio prop replaces width/height for aspect ratio controlobject-fit default changed to coveronBeforeGtmStart callback timing changedFull migration guide: v1 Migration Guide
There are a few areas I'm excited to explore:
I'd like to thank the community for their patience and feedback in getting the module to where it is today. The 30+ contributors and everyone who filed issues and tested pre-releases made this possible.
I hope Nuxt Scripts helps you build faster, more private apps for your users.