Getting Started

Introduction

Nuxt Scripts is Nuxt DX for third-party scripts.

Nuxt Scripts enhances the performance, privacy, and developer experience (DX) when incorporating third-party scripts into Nuxt applications.

Background

Using the useHead composable to load third-party IIFE scripts is straightforward, but complexities arise with server-side rendering (SSR), lazy loading, and type safety. Nuxt Scripts addresses these challenges by optimizing third-party script integration to improve performance, privacy, and overall DX.

Third-Party Script Challenges

  • Compatibility across client and server-side environments.
  • Application of best-practice defaults.
  • Granular optimization controls.
  • Avoiding render-blocking, privacy issues, and performance bottlenecks.
  • Ensuring type safety and script validation.
  • Security considerations with third-party servers.

How Third Parties Can Impact User Experience

Third-party resources like analytics tools, video embeds, maps, and social media integrations enhance website functionality but aren't directly managed by site owners. A single resource may have a minimal performance impact, but multiple resources can significantly degrade user experience. Scripts, in particular, can delay interactivity and obstruct page rendering.

According to the Chrome User Experience Report, Nuxt sites with numerous third-party resources typically show lower Interaction to Next Paint (INP) and Largest Contentful Paint (LCP) scores. Despite the correlation not proving causation, lab tests and the Web Almanac confirm significant performance impacts from third-party resources.

Nuxt Script Features

๐ŸŽ๏ธ Performance

  • Script loading is triggered only when Nuxt is ready, by default.
  • More advanced triggering of script loads, independent of implementation specifics.
  • Improved script loading times with Bundling Remote Scripts.

๐Ÿ˜Œ Developer Experience

  • A curated script registry for common third-party applications.
  • Simplified analytics event management, e.g., tracking page views.
  • Input validation for script options.
  • Type safety and SSR-compliant APIs.

๐Ÿ”’ Privacy

  • Minimize user data exposure by Bundling Remote Scripts.
  • Integrated consent management.
  • Enhanced script privacy settings such as crossorigin="anonymous" and referrerpolicy="no-referrer".