# Third-party script strategies

Feature 12 of 14, in the group "Other features". Labels across 23 meta-frameworks: 5 1st-party, 0 Experimental, 1 Third-party, 17 Manual.

## What it is and why it matters

Third-party scripts (analytics, chat widgets, tag managers) compete with your own code. A loading strategy says when each one loads, for example before hydration, after hydration, or at browser idle time. No first-party script primitive is documented for most frameworks here, so ordering and deferral are left to the app.

## Gotchas

- Without a strategy API, ordering and deferral are your job: put `async`/`defer` and placement choices in the tag yourself.

## Labels

| Framework | Label | Points |
| --- | --- | --- |
| [Next](https://framework-compare.vercel.app/frameworks/next.md) | 1st-party | 2 |
| [Nuxt](https://framework-compare.vercel.app/frameworks/nuxt.md) | 1st-party | 2 |
| [SvelteKit](https://framework-compare.vercel.app/frameworks/sveltekit.md) | Third-party | 1 |
| [SolidStart](https://framework-compare.vercel.app/frameworks/solidstart.md) | Manual | 0 |
| [TanStack Start (React)](https://framework-compare.vercel.app/frameworks/tanstack-start-react.md) | Manual | 0 |
| [TanStack Start (Solid)](https://framework-compare.vercel.app/frameworks/tanstack-start-solid.md) | Manual | 0 |
| [Pracht](https://framework-compare.vercel.app/frameworks/pracht.md) | 1st-party | 2 |
| [Waku](https://framework-compare.vercel.app/frameworks/waku.md) | Manual | 0 |
| [Ember](https://framework-compare.vercel.app/frameworks/ember.md) | Manual | 0 |
| [Astro](https://framework-compare.vercel.app/frameworks/astro.md) | 1st-party | 2 |
| [React Router](https://framework-compare.vercel.app/frameworks/react-router.md) | Manual | 0 |
| [Qwik City](https://framework-compare.vercel.app/frameworks/qwik-city.md) | 1st-party | 2 |
| [Angular (SSR)](https://framework-compare.vercel.app/frameworks/angular.md) | Manual | 0 |
| [Marko](https://framework-compare.vercel.app/frameworks/marko.md) | Manual | 0 |
| [Fresh](https://framework-compare.vercel.app/frameworks/fresh.md) | Manual | 0 |
| [Analog](https://framework-compare.vercel.app/frameworks/analog.md) | Manual | 0 |
| [Vike](https://framework-compare.vercel.app/frameworks/vike.md) | Manual | 0 |
| [RedwoodSDK](https://framework-compare.vercel.app/frameworks/redwoodsdk.md) | Manual | 0 |
| [Remix 3](https://framework-compare.vercel.app/frameworks/remix.md) | Manual | 0 |
| [Void (React)](https://framework-compare.vercel.app/frameworks/void-react.md) | Manual | 0 |
| [Void (Vue)](https://framework-compare.vercel.app/frameworks/void-vue.md) | Manual | 0 |
| [Void (Svelte)](https://framework-compare.vercel.app/frameworks/void-svelte.md) | Manual | 0 |
| [Void (Solid)](https://framework-compare.vercel.app/frameworks/void-solid.md) | Manual | 0 |

## How to enable it in each framework

### Next

Label: **1st-party** (2 of 2 points).

Use [`next/script`](https://nextjs.org/docs/app/api-reference/components/script) with `beforeInteractive`, `afterInteractive`, and `lazyOnload` strategies for the App Router. `worker` is experimental, `pages/`-only, and needs `experimental.nextScriptWorkers`. The experimental `@next/third-parties` ([guide](https://nextjs.org/docs/app/guides/third-party-libraries)) wraps common embeds.

```tsx
import Script from 'next/script'

export default function Page() {
  return (
    <>
      <Script src="https://example.com/script.js" strategy="lazyOnload" />
    </>
  )
}
```

*From [the Script docs](https://nextjs.org/docs/app/api-reference/components/script).*

Gotchas:

- Next's `worker` strategy is experimental and `pages/`-only.

### Nuxt

Label: **1st-party** (2 of 2 points).

`@nuxt/scripts` is a separate official module ([modules page](https://nuxt.com/modules/scripts), [GitHub](https://github.com/nuxt/scripts)) with per-script strategy and proxying; [`useScript`](https://scripts.nuxt.com/docs/api/use-script)'s `partytown` option loads a script in a web worker and needs `@nuxtjs/partytown` installed and configured separately.

```ts
const { onLoaded, onError, status } = useScript('https://example.com/sdk.js')
```

*From [the useScript docs](https://scripts.nuxt.com/docs/api/use-script).*

Gotchas:

- Nuxt's `partytown` option needs `@nuxtjs/partytown` installed and configured separately.

### SvelteKit

Label: **Third-party** (1 of 2 points).

No first-party script primitive is documented; the [performance docs](https://svelte.dev/docs/kit/performance) point to [Partytown's SvelteKit integration](https://partytown.qwik.dev/sveltekit/) (community package `@qwik.dev/partytown`) for running third-party scripts in a web worker. Otherwise add the tag in [`app.html`](https://svelte.dev/docs/kit/project-structure) or a component and manage ordering yourself. Not configured in this port.

Example of building it yourself:

Install `@qwik.dev/partytown`, add its Vite plugin, and print the Partytown snippet in the root layout. Scripts tagged `type="text/partytown"` then run in a web worker instead of the main thread.

```js
// vite.config.js
import { sveltekit } from '@sveltejs/kit/vite';
import { partytownVite } from '@qwik.dev/partytown/utils';

export default { plugins: [sveltekit(), partytownVite()] };
```

```svelte
<!-- src/routes/+layout.svelte -->
<script>
	import { partytownSnippet } from '@qwik.dev/partytown/integration';
</script>

<svelte:head>
	<script>
		// Forward the necessary functions to the web worker layer
		partytown = { forward: ['dataLayer.push'] };
	</script>
	{@html '<script>' + partytownSnippet() + '</script>'}
	<script type="text/partytown" src="https://www.googletagmanager.com/gtag/js?id=YOUR-ID-HERE"></script>
</svelte:head>
```

Source: [Partytown: SvelteKit](https://partytown.qwik.dev/sveltekit/)

### SolidStart

Label: **Manual** (0 of 2 points).

No first-party script-loading strategy is documented ([head and metadata](https://docs.solidjs.com/building-apps/head-and-metadata)); `Script` from `@solidjs/meta` only emits a `<script>` tag ([reference](https://docs.solidjs.com/reference/solid-meta/script)). Nothing to enable.

Example of building it yourself:

Write the tags in the port's `Document.tsx`, next to its inline theme script. For a lazy strategy, add an inline loader that injects the third-party script once the page is idle.

```tsx
// src/Document.tsx
const themeScript = `(function(){ /* … from the port … */ })();`;
const lazyAnalytics = `addEventListener("load",function(){(window.requestIdleCallback||setTimeout)(function(){var s=document.createElement("script");s.src="https://example-analytics.com/script.js";s.async=true;document.head.appendChild(s);});});`;

export default function Document(props: ParentProps) {
  return (
    <html lang="en">
      <head>
        {/* … meta, font preload, inlined CSS from the port … */}
        <script>{themeScript}</script>
        <script src="https://example.com/critical.js" async />
        <script>{lazyAnalytics}</script>
        <HydrationScript />
      </head>
      <body>{props.children}</body>
    </html>
  );
}
```

### TanStack Start (React)

Label: **Manual** (0 of 2 points).

Route `head().scripts`, `<Scripts/>`, and `ScriptOnce` emit or run tags but have no loading-strategy API ([production checklist](https://tanstack.com/start/latest/docs/framework/react/guide/production-checklist) only says to review third-party scripts). You wire the tag by hand:

```tsx
head: () => ({
  scripts: [{ children: themeScript }],
}),
```

*From this repo's `tanstack-books/src/routes/__root.tsx` (`optimized` branch; here an inline theme script, but the same field emits any script tag).*

### TanStack Start (Solid)

Label: **Manual** (0 of 2 points).

Same as React ([Solid hosting guide](https://tanstack.com/start/latest/docs/framework/solid/guide/hosting) lists no script API); the same `scripts: [{ children: themeScript }]` field is used in `tanstack-solid-books/src/routes/__root.tsx`.

Example of building it yourself:

Use the root route's `head().scripts`, which the port already uses for its theme script. Since there is no loading-strategy option, add a small inline loader that injects the third-party tag once the page has loaded.

```tsx
// src/routes/__root.tsx
const lazyAnalytics = `addEventListener("load",function(){(window.requestIdleCallback||setTimeout)(function(){var s=document.createElement("script");s.src="https://example-analytics.com/script.js";s.async=true;document.head.appendChild(s);});});`;

export const Route = createRootRoute({
  head: () => ({
    // … meta, links, styles from the port …
    scripts: [
      { children: themeScript },                              // from the port
      { src: "https://example.com/critical.js", async: true }, // load as soon as possible
      { children: lazyAnalytics },                             // like Next's lazyOnload
    ],
  }),
  // …
});
```

### Pracht

Label: **1st-party** (2 of 2 points).

Use [`<Script>`](https://pracht.resynapse.dev/docs/head) from `@pracht/core` with `strategy="beforeHydration" | "afterHydration" (default) | "idle" | "visible"`. On `hydration: "none"` routes only `beforeHydration` runs. This port does not use it; its only script is an inline theme script in the shell's `head()`.

```tsx
import { Script } from "@pracht/core";
// ...
<Script strategy="idle" src="https://example.com/chat-widget.js" />
```

*Adapted from [the head and headers docs](https://pracht.resynapse.dev/docs/head).*

### Waku

Label: **Manual** (0 of 2 points).

The [migration guide](https://waku.gg/guides/migrating-from-nextjs) documents no `next/script` equivalent; nothing to enable.

Example of building it yourself:

React 19 hoists an `<script async src>` rendered anywhere into `<head>` and deduplicates it. For a lazy strategy, write a small client component that injects the tag after load.

```tsx
// src/components/lazy-script.tsx
'use client';
import { useEffect } from 'react';

export function LazyScript({ src }: { src: string }) {
  useEffect(() => {
    const inject = () => {
      if (document.querySelector(`script[src="${src}"]`)) return;
      const s = Object.assign(document.createElement('script'), { src, async: true });
      document.head.append(s);
    };
    const idle = () => ('requestIdleCallback' in window ? requestIdleCallback(inject) : setTimeout(inject));
    if (document.readyState === 'complete') idle();
    else addEventListener('load', idle, { once: true });
  }, [src]);
  return null;
}

// src/pages/_layout.tsx
<script async src="https://example.com/critical.js" />        {/* afterInteractive-ish */}
<LazyScript src="https://example-analytics.com/script.js" />  {/* lazyOnload */}
```

### Ember

Label: **Manual** (0 of 2 points).

The [Vite guide](https://guides.emberjs.com/release/build-tools/vite) covers build setup only and no first-party script primitive is documented; use a script tag in `index.html` or an addon.

Example of building it yourself:

There is no script component, so put the loading strategy in `index.html`. This one waits for the `load` event and an idle moment before it injects the tag, like Next's `lazyOnload`.

```html
<!-- index.html -->
<head>
  <!-- … -->
  <script>
    addEventListener('load', function () {
      (window.requestIdleCallback || setTimeout)(function () {
        var s = document.createElement('script');
        s.src = 'https://example-analytics.com/script.js';
        s.async = true;
        document.head.appendChild(s);
      });
    });
  </script>
</head>
```

### Astro

Label: **1st-party** (2 of 2 points).

Official `@astrojs/partytown` integration: `astro add partytown`, then `type="text/partytown"` on scripts. ([partytown](https://docs.astro.build/en/guides/integrations-guide/partytown/))

Example of building it yourself:

Install the integration with `npx astro add partytown`, then mark scripts `type="text/partytown"` so they run in a web worker. `forward` exposes globals such as `dataLayer.push` to the worker.

```js
// astro.config.mjs
import { defineConfig } from 'astro/config';
import partytown from '@astrojs/partytown';

export default defineConfig({
  integrations: [partytown({ config: { forward: ['dataLayer.push'] } })],
});
```

```astro
<!-- src/layouts/Layout.astro -->
<script type="text/partytown" src="https://example.com/analytics.js"></script>
```

Source: [Astro: @astrojs/partytown](https://docs.astro.build/en/guides/integrations-guide/partytown/)

### React Router

Label: **Manual** (0 of 2 points).

No first-party strategy documented; `<Scripts>` renders the app runtime and only spreads attributes (`crossOrigin`, `nonce`), with no `async`/`defer` strategy documented. ([Scripts](https://reactrouter.com/api/components/Scripts))

Example of building it yourself:

`<Scripts />` only renders the app runtime, so write the tags yourself: `async` in `Layout` for early scripts, or inject in a `useEffect` after hydration.

```tsx
// app/root.tsx
import { useEffect } from 'react'
// …
export function Layout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <head>
        {/* … */}
        {/* React 19 hoists and de-duplicates <script async src> */}
        <script async src="https://plausible.io/js/script.js" data-domain="books.example" />
      </head>
      {/* … */}
    </html>
  )
}

export default function App() {
  useEffect(() => {
    // Client only, after hydration: load the chat widget when the browser is idle.
    ;(window.requestIdleCallback ?? setTimeout)(() => {
      const s = document.createElement('script')
      s.src = 'https://widget.example.com/chat.js'
      s.async = true
      document.body.append(s)
    })
  }, [])
  // …
}
```

Source: [React: the script component](https://react.dev/reference/react-dom/components/script)

### Qwik City

Label: **1st-party** (2 of 2 points).

`qwik add partytown` (CLI integration shipped in `@builder.io/qwik`; it installs `@qwik.dev/partytown`, published from the QwikDev/partytown repo): render `QwikPartytown` with `forward=[...]`, mark scripts `type="text/partytown"`. The docs page itself names no npm package. ([partytown](https://qwik.dev/docs/integrations/partytown/))

Example of building it yourself:

`qwik add partytown` creates a `QwikPartytown` component. Render it in the head with the globals to forward, and mark scripts `type="text/partytown"` so they run in a web worker.

```tsx
// src/root.tsx
import { QwikPartytown } from './components/partytown/partytown'
// …
<head>
  <QwikPartytown forward={['gtag', 'dataLayer.push']} />
  <script async type="text/partytown"
          src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX" />
  <RouterHead />
</head>
```

Source: [Qwik: Partytown](https://qwik.dev/docs/integrations/partytown/)

### Angular (SSR)

Label: **Manual** (0 of 2 points).

No first-party script-loading primitive documented (the runtime-performance page lists none). Rests on absence. ([runtime-performance](https://angular.dev/best-practices/runtime-performance))

Example of building it yourself:

Put the loading strategy in the tag yourself: `async` in `src/index.html` for early scripts, or `afterNextRender` to inject one after the first browser render.

```ts
// src/index.html: loads in parallel, runs as soon as it arrives
// <script async src="https://plausible.io/js/script.js" data-domain="books.example"></script>

// src/app/app.ts: load a chat widget only in the browser, after first render
import { Component, afterNextRender } from '@angular/core';

@Component({ selector: 'app-root', templateUrl: './app.html' })
export class App {
  constructor() {
    afterNextRender(() => {
      // Never runs during SSR; wait for idle so the widget doesn't compete with hydration.
      (window.requestIdleCallback ?? setTimeout)(() => {
        const s = document.createElement('script');
        s.src = 'https://widget.example.com/chat.js';
        s.async = true;
        document.body.append(s);
      });
    });
  }
}
```

Source: [afterNextRender](https://angular.dev/api/core/afterNextRender)

### Marko

Label: **Manual** (0 of 2 points).

`<script>` is effect-like, not a loader; `<html-script>` emits a raw tag. No loading strategies documented. ([core-tag](https://markojs.com/docs/reference/core-tag))

Example of building it yourself:

Marko's `<script>` is a mount effect, so you use `<html-script>` for a literal async tag. A `<script>` effect then loads the low-priority widget at browser idle.

```marko
// src/routes/+layout.marko
<head>
  // …
  // literal tag in the HTML: downloads in parallel, never blocks parsing
  <html-script async src="https://analytics.example.com/script.js"></html-script>
</head>
<body>
  <${input.content}/>
  // runs once in the browser after mount, then waits for idle
  <script>
    (window.requestIdleCallback || setTimeout)(() => {
      const s = document.createElement("script");
      s.src = "https://widget.example.com/chat.js";
      s.async = true;
      document.head.append(s);
    });
  </script>
</body>
```

Source: [Marko core tags](https://markojs.com/docs/reference/core-tag)

### Fresh

Label: **Manual** (0 of 2 points).

No first-party script primitive documented; the head page lists `<script>` with no loading-strategy guidance. ([head](https://usefresh.dev/docs/advanced/head))

Example of building it yourself:

You write the loading strategy into `<head>` in `_app.tsx`. Use `async` or `defer` on the tag, or inject it at idle time with an inline script, as the port does for its theme script.

```tsx
// routes/_app.tsx
const loadChatWhenIdle = `(window.requestIdleCallback||setTimeout)(function(){
  var s=document.createElement("script");s.src="https://widget.example.com/chat.js";s.async=true;
  document.head.appendChild(s);});`;

export default define.page(function App({ Component }) {
  return (
    <html lang="en">
      <head>
        {/* … */}
        <script async src="https://analytics.example.com/script.js" />      {/* parallel, non-blocking */}
        <script dangerouslySetInnerHTML={{ __html: loadChatWhenIdle }} />   {/* after load, at idle */}
      </head>
      {/* <head> sits outside <Partial>, so f-client-nav does not re-run these */}
      <body f-client-nav>{/* … */}</body>
    </html>
  );
});
```

Source: [Fresh head](https://usefresh.dev/docs/advanced/head)

### Analog

Label: **Manual** (0 of 2 points).

No first-party script-loading primitive documented in the Analog docs. ([server-side-rendering](https://analogjs.org/docs/features/server/server-side-rendering))

Example of building it yourself:

Write the loading strategy yourself: `async` in `index.html` for early scripts, or `afterNextRender` to inject one in the browser after the first render.

```ts
// index.html: loads in parallel, runs as soon as it arrives
// <script async src="https://plausible.io/js/script.js" data-domain="books.example"></script>

// src/app/app.component.ts: load a chat widget only in the browser
import { Component, afterNextRender } from '@angular/core';
import { RouterOutlet } from '@angular/router';

@Component({ selector: 'app-root', imports: [RouterOutlet], template: '<router-outlet />' })
export class AppComponent {
  constructor() {
    afterNextRender(() => {
      const s = document.createElement('script');
      s.src = 'https://widget.example.com/chat.js';
      s.async = true;
      document.body.append(s);
    });
  }
}
```

Source: [Angular: afterNextRender](https://angular.dev/api/core/afterNextRender)

### Vike

Label: **Manual** (0 of 2 points).

No first-party script-loading strategy documented; `+Head` and `+client.js` are where scripts are added by hand. ([head-tags](https://vike.dev/head-tags))

Example of building it yourself:

Put scripts that should load early in `+Head` with `async`. Load the rest from `+client.ts` once the page has loaded and the browser is idle.

```tsx
// pages/+Head.tsx
export function Head() {
  return <script async src="https://example.com/critical.js" />
}

// pages/+client.ts
addEventListener('load', () => {
  requestIdleCallback(() => {
    const s = document.createElement('script')
    s.src = 'https://example-analytics.com/script.js'
    s.async = true
    document.head.append(s)
  })
})
```

Source: [Vike: Head tags](https://vike.dev/head-tags) · [Vike: +client.js](https://vike.dev/client)

### RedwoodSDK

Label: **Manual** (0 of 2 points).

No first-party script-loading strategy documented; scripts go in the Document by hand, and the security page covers only the CSP nonce they need. ([documents](https://docs.rwsdk.com/guides/frontend/documents), [security](https://docs.rwsdk.com/core/security))

Example of building it yourself:

Write the tags in the Document yourself. An external script gets `async`, and an inline snippet needs the per-request `rw.nonce` to pass the CSP. Add the script's host to `script-src` in `src/app/headers.ts`.

```tsx
// src/app/Document.tsx
export const Document = ({ rw, children }) => (
  <html lang="en">
    <head>
      {/* … */}
      <script async src="https://plausible.io/js/script.js" data-domain="books.example" />
    </head>
    <body>
      {children}
      <script nonce={rw.nonce}>
        {`window.plausible = window.plausible || function () { (plausible.q = plausible.q || []).push(arguments) };`}
      </script>
      <script>import("/src/client.tsx")</script>
    </body>
  </html>
);
```

Source: [RedwoodSDK: Security](https://docs.rwsdk.com/core/security) · [RedwoodSDK: Documents](https://docs.rwsdk.com/guides/frontend/documents)

### Remix 3

Label: **Manual** (0 of 2 points).

No first-party script-loading strategy documented; add `<script>` tags to the document by hand. ([rendering-ui](https://docs.remix.run/rendering-ui/))

Example of building it yourself:

There is no script loader. Put the `<script>` tag in the document shell's `<head>` with `async` or `defer`.

```tsx
// app/actions/document.tsx
export function Document(handle: Handle<DocumentProps>) {
  return () => (
    <html lang="en">
      <head>
        <meta charSet="utf-8" />
        <title>{handle.props.title ?? "Books"}</title>
        {/* … import map, module preloads, entry script */}
        <script async src="https://plausible.io/js/script.js" data-domain="books.example.com"></script>
      </head>
      <body>{handle.props.children}</body>
    </html>
  );
}
```

Source: [Remix: Rendering UI, document shells and head content](https://docs.remix.run/rendering-ui/#document-shells-and-head-content)

### Void (React)

Label: **Manual** (0 of 2 points).

No first-party script-loading strategy documented. `head()` and middleware `headDefaults` accept `script` entries, which add tags by hand, and Markdown pages take a `<script>` block. ([head](https://void.cloud/guide/pages-routing/head), [markdown](https://void.cloud/guide/pages-routing/markdown))

Example of building it yourself:

Void has no script-loading strategy. Add the tag from `head` with `defer` or `async`.

```ts
// pages/layout.server.ts or any page's .server.ts
import { defineHead } from 'void'

export const head = defineHead(() => ({
  script: [{ src: 'https://example.com/analytics.js', defer: 'defer' }],
}))
```

Source: [Void: Head](https://void.cloud/guide/pages-routing/head)

### Void (Vue)

Label: **Manual** (0 of 2 points).

No first-party script-loading strategy documented. `head()` and middleware `headDefaults` accept `script` entries, which add tags by hand, and Markdown pages take a `<script>` block. ([head](https://void.cloud/guide/pages-routing/head), [markdown](https://void.cloud/guide/pages-routing/markdown))

Example of building it yourself:

Void has no script-loading strategy. Add the tag from `head` with `defer` or `async`.

```ts
// pages/layout.server.ts or any page's .server.ts
import { defineHead } from 'void'

export const head = defineHead(() => ({
  script: [{ src: 'https://example.com/analytics.js', defer: 'defer' }],
}))
```

Source: [Void: Head](https://void.cloud/guide/pages-routing/head)

### Void (Svelte)

Label: **Manual** (0 of 2 points).

No first-party script-loading strategy documented. `head()` and middleware `headDefaults` accept `script` entries, which add tags by hand, and Markdown pages take a `<script>` block. ([head](https://void.cloud/guide/pages-routing/head), [markdown](https://void.cloud/guide/pages-routing/markdown))

Example of building it yourself:

Void has no script-loading strategy. Add the tag from `head` with `defer` or `async`.

```ts
// pages/layout.server.ts or any page's .server.ts
import { defineHead } from 'void'

export const head = defineHead(() => ({
  script: [{ src: 'https://example.com/analytics.js', defer: 'defer' }],
}))
```

Source: [Void: Head](https://void.cloud/guide/pages-routing/head)

### Void (Solid)

Label: **Manual** (0 of 2 points).

No first-party script-loading strategy documented. `head()` and middleware `headDefaults` accept `script` entries, which add tags by hand, and Markdown pages take a `<script>` block. ([head](https://void.cloud/guide/pages-routing/head), [markdown](https://void.cloud/guide/pages-routing/markdown))

Example of building it yourself:

Void has no script-loading strategy. Add the tag from `head` with `defer` or `async`.

```ts
// pages/layout.server.ts or any page's .server.ts
import { defineHead } from 'void'

export const head = defineHead(() => ({
  script: [{ src: 'https://example.com/analytics.js', defer: 'defer' }],
}))
```

Source: [Void: Head](https://void.cloud/guide/pages-routing/head)

---

HTML version: https://framework-compare.vercel.app/features/third-party-scripts · All pages: https://framework-compare.vercel.app/llms.txt · Data: https://framework-compare.vercel.app/api/index.json
