v1 稳定版已发布

第三方脚本
与 Nuxt DX 的结合

以更好的性能、隐私、安全性和开发体验加载第三方脚本,并开箱提供大量常见服务。

更好的 Web 指标

默认采用最佳实践,在需要时再加载脚本,避免阻塞 Nuxt 应用的渲染。

保护用户隐私

避免将用户数据泄露给并不需要这些数据的第三方脚本,并帮助脚本保持符合 GDPR。

安全接入第三方

保护你的应用免受可能被攻陷的第三方脚本影响。

具备 恰到好处 魔法的强大 API

Nuxt Scripts 在第三方脚本之上提供一层抽象,带来 SSR 支持和类型安全,同时仍让你完全掌控脚本的加载方式。

用 Facade 组件提速

Nuxt Scripts 开箱提供多个 Facade 组件

Facade 组件是一种占位式 UI,在第三方脚本加载后才会被替换;它们能显著提升性能,同时仍保留良好的用户体验,不过也存在 取舍 .

Google Maps

Nuxt Scripts11.9x Faster
70ms
Iframe
830ms

YouTube

Nuxt Scripts46.4x Faster
70ms
Iframe
3.3s

Vimeo

Nuxt Scripts3.7x Faster
70ms
Iframe
260ms

Intercom

Nuxt Scripts3.9x Faster
220ms
Iframe
850ms

*请注意,PageSpeed Insights 的实验室数据只是某一天的快照,通常会有波动。

按服务商类型化的 Cookie 同意管理

每个支持同意管理的脚本都会返回一个与服务商原生 API 对应的 consent 对象,并在首次调用前应用 defaultConsent

包括 Google Consent Mode v2、Meta grant/revoke、Matomo give/forget、TikTok 三态模式等。你也可以对接 OneTrust 或 Cookiebot,或者使用 useScriptTriggerConsent 自己实现横幅。

隐私优先的社交嵌入

无需加载第三方脚本即可嵌入 X、Instagram 和 Bluesky 的帖子。所有内容都由服务端获取,并通过你的域名代理。

零客户端 JavaScript、零 Cookie、零第三方请求。

Nuxt Scripts 对比原生方案
X
Instagram
Bluesky
客户端 JS 0vs475 KB0vs580 KB0vs42 KB
请求数 0vs250vs340vs9
Cookie NovsYesNovsYesNovsNo
阻塞时间 0msvs1,010ms0msvs780ms0msvs60ms
Alexander Lichter
Alexander Lichter

@TheAlexLichter

✨Time to talk about the newest official @nuxt_js module - Nuxt Scripts! And not only covering why it is useful and what it does, but using the underlying `useScript` composable to load a *custom script* right into a demo application. Don't miss it out! 💚 Link below 👇 https://t.co/UjefeB3Ny9

12:30 PM · Aug 30, 20240 回复0 喜欢
Jakub Andrzejewski
Jakub Andrzejewski

@jacobandrewsky.bsky.social

Are you struggling with third party scripts affecting performance of your @nuxt.com application? 🤔 Check out Nuxt Scripts module that brings several solutions to this problem with the amazing Developer Experience! 🚀 scripts.nuxt.com
11:12 AM · Apr 1, 20250 replies0 reposts4 likes

看看专业人士的入门视频。

更快的 Web 协作

Nuxt Scripts 由 Nuxt 核心团队与 Google 的 Chrome Aurora 团队协作设计和构建。

Nuxt Scripts 由 Nuxt 核心团队和优秀的社区贡献者持续维护,欢迎所有贡献。

试试我们的 JS 彩带教程

通过有趣的交互彩带教程学习 Nuxt Scripts 的全部基础。