Skip to solution
mediumFrontend

What is next/script and what are its strategy options in Next.js?

1.1k views
01

Understand the problem

Controlling when third-party scripts load.

nextjsnext-scriptthird-partyperformance
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

next/script loads third-party scripts with a strategy: beforeInteractive (critical, before hydration), afterInteractive (default, after hydration), lazyOnload (idle), and worker (off main thread). It prevents blocking scripts from hurting performance.

Solution ready — 2 min read

Classified // press E to declassify

04

Read the code

Load analytics after interactive
import Script from 'next/script';

// analytics: not critical → after hydration
<Script src="https://analytics.example.com/a.js" strategy="afterInteractive" />;

// chat widget: low priority → when the browser is idle
<Script src="https://chat.example.com/w.js" strategy="lazyOnload" />;
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 17 of 95 decoded in the Next.js track. One more won't hurt.

Back to track