website-logomedCode

Next.js 15 : Introduction to SEO Evolution

Discover how Next.js 15 is revolutionizing modern web development and SEO. Learn the new features that boost performance
MOHAMMED DAKIR| September 7, 2024
next.js
 Next.js 15 : Introduction to SEO Evolution

#Next.js #SEO #Improvement #Web_Dev

Introduction

As the digital world continues to evolve, SEO (Search Engine Optimization) has become more complex and sophisticated. Search engines now prioritize user experience, speed, and accessibility, making frameworks like Next.js crucial in modern web development. Next.js 15, the latest version of this popular React-based framework, brings a variety of features designed to boost performance, improve developer experience, and, most importantly, optimize SEO. Let’s dive into how these new features benefit search engines, especially in the context of server-side rendering (SSR) and static site generation (SSG).

Understanding SSR (Server-Side Rendering)

Definition of SSR

Server-side rendering (SSR) refers to the process of rendering a web page on the server and sending the fully rendered page to the client. This technique allows for faster initial page loads and is beneficial for SEO since search engines can easily crawl and index the content. In contrast to client-side rendering (CSR), SSR delivers pre-rendered HTML content, which provides a more SEO-friendly environment.

How SSR Impacts SEO and User Experience

Search engines, particularly Google, favor pages that load quickly and provide useful content. With SSR, pages are rendered on the server before they reach the user’s browser, reducing the time it takes for content to become visible. This quick rendering not only improves the user experience but also increases the chances of higher search engine rankings.

SSR in Earlier Versions of Next.js vs Next.js 15

Previous versions of Next.js offered robust SSR capabilities. However, Next.js 15 takes it a step further with enhanced server-side rendering performance, making it even more beneficial for SEO. The improvements in caching, incremental regeneration, and reduced server response times have a direct impact on how quickly and effectively search engines can index pages.

What is SSG (Static Site Generation)?

Explanation of SSG

Static Site Generation (SSG) is another method of rendering web pages, but instead of doing it on the server at request time, the pages are pre-rendered at build time. This allows for faster delivery of content since the server simply serves static HTML files. SSG is particularly useful for blogs, portfolios, and documentation sites where content doesn't change often.

SEO Benefits of SSG

The main advantage of SSG from an SEO perspective is its speed. Pre-rendered static pages load almost instantly, which improves page speed metrics — a key ranking factor for search engines. Additionally, these static pages are fully crawlable by search engines, ensuring that content is indexed quickly and effectively.

SEO Best Practices with Next.js 15

Now that we’ve covered the new features of Next.js 15, let's talk about specific strategies to enhance SEO on your Next.js-powered site.

Optimize Meta Tags

Static Metadata

To define static metadata, you export a Metadata object from a layout.ts or page.ts file using the App Router.

Example:

import { Metadata } from "next";

export const metadata: Metadata = {
 metadataBase: new URL("https://www.domaine.com"),
 title: "Static Page Title",
 description: "This is a static page description",
 keywords:["word1","word2","word3"],
 applicationName: "Next.js seo",
 category: "category app",
 creator: "your name",
};

export default function Page() {}

Dynamic Metadata

Dynamic metadata allows you to generate metadata based on dynamic data, such as route parameters or fetched data.

Example:

import React from "react";
import { getPostsBySlug, FormatDate } from "@/app/utils/action";

export async function generateMetadata({ params }) {
  const post = await getPostsBySlug(params.slug);
  const publishedAt = new Date(post?.createdAt).toISOString();
  const modifiedAt = new Date(post?.updatedAt || post?.createdAt).toISOString();
  return {
    title: post?.title,
    description: post?.description,
    keywords: post?.tags,
    publishedTime: publishedAt,
    modifiedTime: modifiedAt,
    robots: {
      index: true,
      follow: true,
    },
    alternates: {
      canonical: `/blogs/${params.slug}`,
      languages: {
        "en-US": `en-US/blogs${params.slug}`,
      },
      types: {
        "application/rss+xml": "https://www.medcode.dev/rss",
      },
    },
    local: "en_Us",
    type: "article",
    openGraph: {
      title: post?.title,
      description: post?.description,
      publishedTime: publishedAt,
      modifiedTime: modifiedAt,
      images: [
        {
          url: post?.image,
          width: "400",
          height: "300",
        },
      ],
    },
  };
}
const BlogPage = async ({ params }) => {}
export default BlogPage;

Optimize Images

Images can significantly impact page load times, and Next.js 15 offers built-in image optimization. By automatically serving appropriately sized images and compressing them for the web, Next.js helps reduce load times and improve your site's SEO.

function Component() {
  return (
    <Image src='https://ik.imagekit.io/your_imagekit_id/image_NDIXZTQle.jpg'alt='Sample image'
width={400}
height={400
/> ); }

Asset Flexibility

module.exports = {
  images: {
    remotePatterns: [
      {
        protocol: 'https',
        hostname: 's3.amazonaws.com',
        port: '',
        pathname: '/your-bucket-name/**',
      },
    ],
  },
}

With this configuration, you can use the image URL in the following format:

<Image src="https://s3.amazonaws.com/your-bucket-name/image.png"alt="Picture of the author"width={500}         height={500}
/>

Faster Page Loads : priority

import Image from 'next/image'

function Component() {
  return (
    <Imagesrc='/image.jpg'alt='Sample image'width={400}height={400}priority={true}
    />
  );
}

Lazy Load Scripts

Third-party scripts, which in reality destroy page performance, are frequently seen on jamstack websites. These scripts include Google Tag Manager, cookie consent managers, newsletter pop-ups, and other tools. If you want your page speed insights score to be as high as possible, you should strongly consider eliminating some of them.

Even the best-optimized website may do poorly in a Google Pagespeed Insight test if it is using an excessive number of scripts. Certain third-party scripts can significantly impair the user experience and have a significant impact on how quickly a website loads, particularly if they render-block or cause page content to load slowly.

load the page before it becomes interactive (beforeInteractive).

A script can run ahead of the self-bundled JavaScript by injecting it into the server's first HTML. If there are any essential scripts that must load and run before the page can be interacted with, use this approach.

Bot detectors and third-party libraries that need to load before the JavaScript code executes are examples of scripts that usually need this loading technique. Recall that this tactic is only applicable to scripts contained in the Next.js custom document component.

Create a Sitemap and Robots.txt

A sitemap is essential for helping search engines understand the structure of your website. With Next.js 15, generating a sitemap and a robots.txt file is straightforward, ensuring that search engines can crawl your site efficiently.

  1. sitemap.js: create file sitemap.js in app directory and pas this example :
export default function sitemap() {
 return [
  {
   url: 'https://acme.com',
   lastModified: new Date(),
   changeFrequency: 'yearly',
   priority: 1,
  },
  {
   url: 'https://acme.com/about',
   lastModified: new Date(),
   changeFrequency: 'monthly',
   priority: 0.8,
  },
  {
   url: 'https://acme.com/blog',
   lastModified: new Date(),
   changeFrequency: 'weekly',
   priority: 0.5,
  },
 ]
}

2.roboto.txt : create a file roboto.txt in the app directory :

 export default function robots() {
    return {
      rules: {
        userAgent: "*",
        allow: "/",
        disallow: "/private/"
      },
      sitemap: "https://www.domaine.com/sitemap.xml",
    };
  }
Share

Explore the latest insights, articles,free components, and expert advice on programming and software development

© Copyright 2024 MED DAKIR. All rights reserved./privacy policyTerms & Conditions