Approach
The Pages Router integration uses the Next.js built-inScript component to load the CDN bundle. Unlike the App Router approach, which appends a <script> element programmatically via useEffect, the Pages Router pattern declares the script declaratively in _app.tsx and relies on the onLoad callback to run initialization code after the script is ready.
Update _app.tsx
Open (or create) Replace
pages/_app.tsx and add the Script component with an onLoad callback:"YOUR_PUBLIC_KEY_HERE" with your public key from the JigsawStack dashboard.How it works
TheonLoad callback is invoked by Next.js after the CDN script has fully loaded and executed. At that point, window.TranslationWidget is available and you can call it with your public key and configuration.
The Next.js
Script component handles deferred loading automatically. You do not need to add a defer attribute — Next.js manages script loading strategy internally to avoid blocking page rendering.App Router vs. Pages Router
| App Router (Next.js 13+) | Pages Router (Next.js ≤12) | |
|---|---|---|
| Setup file | app/layout.tsx | pages/_app.tsx |
| Script loading | Programmatic via document.createElement in useEffect | Declarative via Next.js <Script> component |
| Initialization | script.onload + window.addEventListener("load", ...) | onLoad callback on <Script> |
| Cleanup | Manual removal on unmount | Managed by Next.js |