✦ Auto-train your AI from your URLTry it free →
Next.js logo
Guide

Next.js AI Chat Widget

Next.js teams obsess over Core Web Vitals, so any third-party script has to prove it will not touch the critical rendering path. The framework's built-in next/script component exists for exactly this, and it is the right way to add a chat widget to a Next.js app.

EasyChatWidget drops into your root layout through next/script with the afterInteractive strategy, loading only once the page is interactive so first paint is never delayed. The same setup covers the App Router and the Pages Router, and the AI answers from content you train it on.

Why add EasyChatWidget to Next.js

  • Loads through next/script, keeping first paint and Core Web Vitals clean
  • One placement in your layout covers every route in either router
  • Tune timing with afterInteractive or lazyOnload as you prefer
  • Answers from your content and hands off to a human on request

Best for: Next.js use cases

SaaS & marketing sites

Answer plan and feature questions without a byte on the critical path.

E-commerce storefronts

Support headless Next.js shops with product and delivery answers.

Content & docs sites

Help readers find the right page across a large content set.

High-traffic apps

Add support that scales without adding render cost per visit.

How to install the chat widget on Next.js

  1. 1
    Import next/script
    Use the built-in <Script> component for proper loading order.
  2. 2
    Add it to your layout
    Place the <Script> in app/layout.js (App Router) or _app.js (Pages Router) as shown below.
  3. 3
    Pick a loading strategy
    afterInteractive (shown) loads the widget once the page is interactive. For a chat widget you can also use strategy="lazyOnload" to defer it to browser idle time - even lighter on initial load.

Your embed snippet

Copy this and follow the steps above.

import Script from 'next/script'

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        {children}
        <Script
          src="https://easychatwidget.com/widget.js"
          data-widget-id="YOUR_WIDGET_ID"
          strategy="afterInteractive"
        />
      </body>
    </html>
  )
}
Note
Replace YOUR_WIDGET_ID with the ID from your dashboard. Don’t have one yet? Create a free account to get it.

See the Next.js chat widget in action

Next.js homepage - add the EasyChatWidget AI chat widget to Next.js
Next.js, where the EasyChatWidget AI chat widget goes live in minutes.

EasyChatWidget vs. building chat yourself

How the EasyChatWidget AI chat widget compares with building chat yourself on Next.js.

Feature comparison of EasyChatWidget versus building chat yourself on Next.js
FeatureEasyChatWidgetbuilding chat yourself
Understands and answers questions with AI
Trains itself on your website automatically
Answers from your own content (no invented facts)
Replies in any visitor languageManual only
Captures leads (name, email, question)Varies
Installs with a single snippet
Full colour, position & branding controlLimited
Instant human handoff by email & WhatsApp

Next.js chat widget FAQ

How do I add a chat widget to a Next.js app?
Use the built-in next/script <Script> component in app/layout.js (App Router) or _app.js (Pages Router), pointing it at the EasyChatWidget script with your widget ID and the afterInteractive strategy.
Which next/script strategy is best?
afterInteractive is a solid default - it loads once the page is interactive. For the lightest initial load, lazyOnload defers the widget to browser idle time.
Does it support both the App Router and Pages Router?
Yes. Add the Script to app/layout.js for the App Router or _app.js for the Pages Router and it loads on every route.
Will it hurt my Core Web Vitals?
No. Loading through next/script keeps it off the critical path, so LCP and the rest of your Core Web Vitals are unaffected.

Learn more

Related integrations

Add your Next.js chat widget in 60 seconds

Create your free account, paste the snippet, and your AI chat widget starts answering visitors immediately.

Get started free

7-day free trial · No credit card required