Skip to content
bellona

Guide

Next.js SEO checklist

Next.js builds pages on the server, which already gives search engines the complete text in the first response. The rest of Next.js SEO is a checklist: correct metadata, one canonical address per page, a real sitemap, a robots file, structured data, fast images and fonts, and redirects. This guide lists each item with code for the App Router.

By: Amirhossein Bazdar, CTOLast updated:

Why is Next.js SEO easier to get right?

Next.js renders each page on the server, so the full HTML text is in the first response and a search engine, or an AI assistant that does not run JavaScript, can read it immediately. It also gives you direct control of metadata, sitemaps, robots, redirects and image optimization, which are the main SEO levers.

A page that builds its text in the browser forces the crawler to run JavaScript before it sees anything. Server rendering (or static generation) removes that step. It is the reason most of our own sites, including this one, are built with Next.js.

How do you set titles, descriptions and canonical tags?

With the Metadata API: set site-wide defaults and a title template in the root layout, and a generateMetadata function on dynamic pages. Give every page a unique title and description, one canonical address, and set metadataBase so relative URLs become absolute.

// app/layout.tsx: site-wide defaults
import type { Metadata } from "next";

export const metadata: Metadata = {
  metadataBase: new URL("https://example.com"),
  title: { default: "Example | What we do", template: "%s · Example" },
  description: "One clear sentence about what the site offers.",
};

// app/services/[slug]/page.tsx: per-page metadata
export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise<Metadata> {
  const { slug } = await params;
  const service = await getService(slug);
  return {
    title: service.title,
    description: service.description,
    alternates: { canonical: `/services/${slug}` },
    openGraph: { type: "website", title: service.title, description: service.description, url: `/services/${slug}` },
  };
}

How do you add hreflang for two languages?

In the same metadata object, under alternates.languages, list each language's address plus x-default. Every language version must list the full set, and each version's canonical points to itself. The bilingual guide explains the rules and the common mistakes.

alternates: {
  canonical: "/services",
  languages: { fa: "/services", en: "/en/services", "x-default": "/services" },
},

How do you generate a sitemap with real dates?

Add app/sitemap.ts that returns every public URL, with lastModified set to the date the content really changed, never the build time. Include each language's alternates, leave out redirected, noindex and API URLs, and generate the list from the same data source that builds the pages.

// app/sitemap.ts
import type { MetadataRoute } from "next";
import { getAllServices } from "@/lib/content";

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
  const services = await getAllServices();
  return services.map((s) => ({
    url: `https://example.com/services/${s.slug}`,
    lastModified: s.updatedAt, // the real update date
    alternates: { languages: { fa: `https://example.com/services/${s.slug}`, en: `https://example.com/en/services/${s.slug}` } },
  }));
}

What should robots.txt contain?

Allow crawling of the site, point to the sitemap, and disallow only what has no value in search, such as your API routes. Keep the generated Open Graph image route allowed so link previews work. Do not block CSS or JavaScript files that pages need to render.

// app/robots.ts
import type { MetadataRoute } from "next";

export default function robots(): MetadataRoute.Robots {
  return {
    rules: [{ userAgent: "*", allow: ["/", "/api/og"], disallow: ["/api/"] }],
    sitemap: "https://example.com/sitemap.xml",
  };
}

How do you add structured data (JSON-LD)?

Render a small component that outputs a script tag of type application/ld+json, with values taken from the real page data. Use an Organization on every page, a Service or Article where it applies, and a BreadcrumbList that matches the visible breadcrumb. Never add data that the page does not show.

// components/JsonLd.tsx
export function JsonLd({ data }: { data: object }) {
  return (
    <script
      type="application/ld+json"
      // "<" is escaped so content can never close the script tag
      dangerouslySetInnerHTML={{ __html: JSON.stringify(data).replace(/</g, "\\u003c") }}
    />
  );
}

// usage on a service page
<JsonLd
  data={{
    "@context": "https://schema.org",
    "@type": "Service",
    name: service.title,
    description: service.description,
    provider: { "@id": "https://example.com/#organization" },
  }}
/>

How do you optimize images?

Use next/image with honest width and height so nothing shifts, give a sizes attribute so a phone does not download a desktop-sized file, mark the first large image on the page priority, and write descriptive alt text. Decorative images get an empty alt.

import Image from "next/image";

// The first large image on the page is usually the LCP: mark it priority and give honest sizes
<Image
  src="/work/project/cover.jpg"
  alt="Descriptive text of what the image shows"
  width={1440}
  height={900}
  priority
  sizes="(min-width: 1024px) 800px, 100vw"
/>

What about fonts and heavy libraries?

Load fonts with next/font so they are self-hosted and do not shift the layout, use font-display swap and only the weights you use. Load heavy libraries such as animation or 3D only on the pages that need them, using dynamic imports, so service and article pages stay light.

import dynamic from "next/dynamic";
import localFont from "next/font/local";

export const body = localFont({ src: "./fonts/Body.woff2", display: "swap" });

// Only the pages that render the 3D scene pay for it
const Scene = dynamic(() => import("@/components/Scene"));

How do you handle redirects and 404s?

Define permanent redirects in next.config, one hop each, and let unknown dynamic URLs return a real 404 by setting dynamicParams to false and calling notFound(). A page that returns 200 with a "not found" message (a soft 404) is worse than a true 404.

// next.config.ts
async redirects() {
  return [{ source: "/old-page", destination: "/new-page", permanent: true }];
},

// app/services/[slug]/page.tsx
export const dynamicParams = false; // unknown slugs return a real 404
export function generateStaticParams() { return getAllServices().map((s) => ({ slug: s.slug })); }

How do you test every item?

View the page source and check that the text, title, canonical, hreflang and JSON-LD are all in the raw HTML. Fetch the sitemap and robots with curl, run Lighthouse on mobile for speed, validate structured data, and crawl the site for broken links. Then watch Search Console after launch.

  1. curl the page: is the text, title and JSON-LD in the first response?
  2. Check canonical and hreflang reciprocity for every page
  3. Fetch /sitemap.xml and /robots.txt and read them
  4. Run Lighthouse on mobile: LCP under 2.5 s, CLS under 0.1
  5. Validate structured data and fix every warning
  6. Crawl for broken internal links and redirect chains
  7. Submit the sitemap and monitor Search Console

Where do teams most often go wrong?

Forgetting metadataBase so canonicals are relative, a sitemap that uses the build time for every date, hreflang that does not link back, structured data that disagrees with the page, images without a sizes attribute, and a staging noindex that is still on after launch. All are caught by the tests above.

Can Bellona audit or build this for us?

Yes. We build Next.js sites with this checklist from the start and can audit an existing one. The free growth audit tells you what to fix first and, if it fits, you get a fixed quote in writing.

LET'S TALK

Ready when
you are.

Tell us where it hurts. You get a free 30-minute growth audit and, if it fits, a fixed quote.

Prefer to pick a time?

Book a free growth audit

Or email bellona.ai.team@gmail.com

What do you need?

We only use this to reply to you.