<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Next.js - OhMyCrawl</title>
	<atom:link href="https://www.ohmycrawl.com/category/nextjs/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.ohmycrawl.com/category/nextjs/</link>
	<description>Digital Architecture For Search Engines</description>
	<lastBuildDate>Fri, 07 Aug 2026 16:22:25 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.3</generator>

<image>
	<url>https://www.ohmycrawl.com/wp-content/uploads/2022/10/cropped-ohmycrawl1-32x32.png</url>
	<title>Next.js - OhMyCrawl</title>
	<link>https://www.ohmycrawl.com/category/nextjs/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>NextJS Head: Optimize MetaData</title>
		<link>https://www.ohmycrawl.com/nextjs/head/</link>
					<comments>https://www.ohmycrawl.com/nextjs/head/#respond</comments>
		
		<dc:creator><![CDATA[ScottySEO]]></dc:creator>
		<pubDate>Sun, 11 Jun 2023 16:21:40 +0000</pubDate>
				<category><![CDATA[Next.js]]></category>
		<guid isPermaLink="false">https://www.ohmycrawl.com/?p=20953</guid>

					<description><![CDATA[<p>Next.js is an alternative to GatsbyJS and is a framework built on React that comes equipped with tooling for server side rendering and static site generation. Long story short, it&#8217;s a great way to leverage React while obtaining excellent Next.js SEO metrics. NextJs ships with a collection of components that help streamline certain aspects of ... <a title="NextJS Head: Optimize MetaData" class="read-more" href="https://www.ohmycrawl.com/nextjs/head/" aria-label="More on NextJS Head: Optimize MetaData">Read more</a></p>
<p>The post <a href="https://www.ohmycrawl.com/nextjs/head/">NextJS Head: Optimize MetaData</a> appeared first on <a href="https://www.ohmycrawl.com">OhMyCrawl</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph"><a href="https://www.ohmycrawl.com/nextjs/">Next.js</a> is an alternative to GatsbyJS and is a framework built on React that comes equipped with tooling for <a href="https://www.ohmycrawl.com/nextjs/server-side-rendering-2/">server side rendering</a> and static site generation. Long story short, it&#8217;s a great way to leverage React while obtaining excellent <a href="https://www.ohmycrawl.com/nextjs/seo/">Next.js SEO</a> metrics.</p>



<p class="wp-block-paragraph">NextJs ships with a collection of components that help streamline certain aspects of development. One such component we&#8217;ll be discussing here is the NextJS Head component, which simplifies injection of metadata into the HTML head tag of your web app. Getting the head tag right is crucial for search engines, much like other aspects we cover such as <a href="https://www.ohmycrawl.com/nextjs/robots-txt-2/">robots.txt</a> and <a href="https://www.ohmycrawl.com/nextjs/sitemap/">sitemaps</a>.</p>



<div class="wp-block-columns has-background is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex" style="background-color:#fff4cf">
<div class="wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:33.33%"><div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><img fetchpriority="high" decoding="async" width="313" height="280" src="https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs.jpg" alt="" class="wp-image-21460" style="aspect-ratio:1.1168831168831168;width:284px;height:auto" srcset="https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs.jpg 313w, https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs-300x268.jpg 300w" sizes="(max-width: 313px) 100vw, 313px" /><figcaption class="wp-element-caption"><em>SEO Consultant </em></figcaption></figure>
</div></div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:66.66%">
<p class="has-text-align-center has-large-font-size wp-block-paragraph">Free Weekly SEO Newsletter</p>



<p class="wp-block-paragraph">Hey! I&#8217;m Scott, I&#8217;ve been an SEO consultant for nearly 10 years. Get on my weekly newsletter to get..</p>



<ul class="wp-block-list">
<li>Weekly SEO updates, keep up with the latest and greatest.</li>



<li>How we grow websites from zero to millions of visitors</li>



<li>A bunch of SEO tips and Tricks you won&#8217;t find anywhere else test</li>
</ul>


<div class="gb-button-wrapper gb-button-wrapper-88826626">

<a class="gb-button gb-button-d3a6a344 gb-button-text" href="#cb717b282f"><strong>Get On The Newsletter</strong></a>

</div></div>
</div>



<h2 class="wp-block-heading">TL;DR: Next JS Head Quick Links</h2>



<p class="wp-block-paragraph">For those of us who want answers quickly:</p>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<ul class="wp-block-list">
<li><a href="#overview-next-js-head">Quick Overview of NextJS Head</a></li>



<li><a href="#static-vs-dynamic-next">NextJs Static Head vs Dynamic Head</a></li>
</ul>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<ul class="wp-block-list">
<li><a href="#next-head-examples">NextJs Head Examples</a></li>



<li><a href="#nextjs-head-meta-important">Important Next/Head Metadata To Include </a></li>
</ul>
</div>
</div>



<h2 class="wp-block-heading">NextJs Head and HTML head</h2>



<p class="wp-block-paragraph">In HTML, the head tag can contain styling, scripting, and a variety of metadata related to a given web page. Modern frameworks like ReactJs and NextJs utilize coding techniques to facilitate the population of data within the HTML head tag.</p>



<h2 class="wp-block-heading">NextJs Head | Controlling the &lt;head&gt; Tag with Nextjs Head</h2>



<p class="wp-block-paragraph">In comes the NextJs &lt;Head /&gt; component, giving developers the ability to configure their own dynamic Head component, or simply configure the head tag statically.</p>



<p class="wp-block-paragraph">This feature is important for front-end frameworks like Next JS. Developers don&#8217;t have direct access to each individual HTML file, and the Head component is how we get our metadata where it needs to be within the head tag.</p>



<h2 class="wp-block-heading" id="nextjs-head-meta-important">Which types of Metadata are important  when using Next/Head?</h2>



<p class="wp-block-paragraph">There are many tags and techniques used within Head to optimize search engine performance. Rather than attempt an exhaustive list (which could probably fill a book), let&#8217;s take a look at some of the most important tags that google really weighs heavily.</p>



<p class="wp-block-paragraph"><em>Note: Going forward, Head is synonymous with the NextJs Head component. While head will refer to the HTML tag.</em>&nbsp;</p>



<h3 class="wp-block-heading">Title Tag&nbsp;</h3>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">&lt;title&gt;Title Goes Here&lt;/title&gt;</p>
</blockquote>



<p class="wp-block-paragraph">The title tag is perhaps the most important metadata found within the head tag. It sends a powerful signal to Google about your content, providing a bite sized phrase defining what your content actually is. If we could optimize only one aspect of the Head, this would be it.</p>



<p class="wp-block-paragraph">The title is shown as the link text in Google search results, and also in browser tabs. A length of 50-60 characters is ideal for the title tag.</p>



<h3 class="wp-block-heading">Meta Description</h3>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">&lt;meta name=&#8217;description&#8217; content=&#8217;Description goes here&#8217; /&gt;</p>
</blockquote>



<p class="wp-block-paragraph">The meta description is perhaps the most underrated meta tag found within the head tag. It is often left blank, leaving Google to extract the description from your page, leading to undesired results.</p>



<p class="wp-block-paragraph">The meta description is displayed underneath the title in Google search results. Since Google usually truncates descriptions at around 155-160 characters, it&#8217;s considered optimal to stay within this range.</p>



<h2 class="wp-block-heading"><strong>&nbsp;</strong></h2>



<h3 class="wp-block-heading">Structured Data&nbsp;</h3>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">&lt;script type=&#8221;application/ld+json&#8221;&gt;{ json: “goes here” }&lt;/script&gt;</p>
</blockquote>



<p class="wp-block-paragraph">Structured data is a way to spoon feed Google information about your site. Googlebot is just a program, and programs can read and process structured data much easier than extracting data from tags.</p>



<p class="wp-block-paragraph">Structured data mostly reflects the metadata found within already existing tags inside the head tag. It&#8217;s programmatically represented using JavaScript object notation (JSON), and is fairly simple to set up.</p>



<h2 class="wp-block-heading" id="next-head-examples">NextJs Head | Basic Example</h2>



<p class="wp-block-paragraph">The NextJs Head component is easy to use. Let&#8217;s take a look at a basic example using our previously discussed tags:</p>



<pre class="wp-block-code"><code>import Head from 'next/head'

function IndexPage() {
  return (
    &lt;div&gt;
      &lt;Head&gt;
        &lt;title&gt;My page title&lt;/title&gt;
        &lt;meta name="viewport" content="initial-scale=1.0, width=device-width" /&gt;
      &lt;/Head&gt;
      &lt;p&gt;Hello world!&lt;/p&gt;
    &lt;/div&gt;
  )
}

export default IndexPage
</code></pre>



<p class="wp-block-paragraph">This simple example was pulled straight from the <a href="https://nextjs.org/docs/api-reference/next/head">NextJs docs</a>. To help illustrate what Next is doing here, take a look at some of the HTML rendered in the browser:</p>



<pre class="wp-block-code"><code>&lt;html&gt;
	&lt;head&gt;
		&lt;title&gt;My page title&lt;/title&gt;
&lt;meta name="viewport" content="initial-scale=1.0, width=device-width" /&gt;
	&lt;/head&gt;
	&lt;body&gt;
		&lt;div&gt;
			&lt;p&gt;Hello world!&lt;/p&gt;
		&lt;/div&gt;
	&lt;/body&gt;
&lt;/html&gt;
</code></pre>



<p class="wp-block-paragraph">As can be seen, NextJs Head simply created an HTML head tag and inserted our metadata. It’s important to note that although the NextJs &lt;Head /&gt; component is located within the &lt;div&gt; tag inside our component, that’s not where it was rendered.&nbsp;</p>



<p class="wp-block-paragraph">NextJs extracts the content within the &lt;Head /&gt; component and moves it to the HTML &lt;head&gt; tag.</p>



<h2 class="wp-block-heading">Why not just create the HTML head tag ourselves?&nbsp;</h2>



<p class="wp-block-paragraph">Don&#8217;t forget, as we went over earlier; when using frameworks like Next, we don&#8217;t have direct access to the HTML file. All HTML is generated at client or server run time, or at build time, when each individual component (such as the one above) is converted into HTML.</p>



<p class="wp-block-paragraph">Therefore, we need the Head component to insert our content properly behind the scenes.</p>



<h2 class="wp-block-heading" id="static-vs-dynamic-next">NextJs Static Head vs Dynamic Head</h2>



<p class="wp-block-paragraph">In the previous example, we created our head tag by providing static information. But this isn&#8217;t very flexible, and doesn&#8217;t lend itself nicely to the DRY (don&#8217;t repeat yourself) principle of coding.</p>



<p class="wp-block-paragraph">Let&#8217;s take a look at creating a dynamic Head component that partially simplifies the process of optimizing for search engines, then discuss what problems it solves.</p>



<h3 class="wp-block-heading">NextJs | Dynamic Head Example</h3>



<p class="wp-block-paragraph">First, we’ll create a file called <em>globalmeta.js </em>that contains data which can be used globally throughout the application:</p>



<p class="wp-block-paragraph"><strong><em>globalmeta.js</em></strong></p>



<pre class="wp-block-code"><code>const globalMeta = {
	siteName: "Your Site Name",
	siteUrl: "https://yoursite.com",
	siteLogo: "https://yoursite.com/images/logo.png",
	email: "email@yoursite.com",
	description: "Default site description."
}

export default globalMeta;
</code></pre>



<p class="wp-block-paragraph">Now, we’ll create our dynamic Head component. Notice it is populated with some optional parameters from our globalmeta.js file we just created:</p>



<p class="wp-block-paragraph"><strong><em>Head.js</em></strong></p>



<pre class="wp-block-code"><code>import Head from 'next/head';
import globalMeta from '../globalmeta';
 
export default function Home({
	title = globalMeta.siteName,
	description = globalMeta.description,
	canonicalUrl = globalMeta.siteUrl,
	ogType,
	ogImgUrl = globalMeta.siteLogo,
	structuredData,
	children
}) {
 
  return (
	&lt;Head&gt;
    	{/*
        	Fundamental head elements.
    	*/}
    	&lt;title&gt;{ title } &lt;/title&gt;
    	&lt;meta name="description" content={description} /&gt;
    	&lt;link rel="canonical" href={canonicalUrl} /&gt;
    	&lt;meta name="viewport" content="width=device-width, initial-scale=1" /&gt;
    	&lt;link rel="icon" href="/favicon.ico" /&gt;
 
    	{/*
        	Open graph meta tags.
    	*/}
    	&lt;meta property="og:locale" content="en_US" /&gt;
    	&lt;meta property="og:site_name" content={globalMeta.siteName} /&gt;
    	&lt;meta property="og:type" content={ogType} /&gt;
    	&lt;meta property="og:description" content={description} /&gt;
    	&lt;meta property="og:image" content={ogImgUrl} /&gt;
    	&lt;meta property="og:url" content={canonicalUrl} /&gt;
 
    	{/*
        	Structured data.
    	*/}
    	&lt;script
            type="application/ld+json"
        	dangerouslySetInnerHTML={{__html: structuredData}}
        	key="item-jsonld"
    	/&gt;
    	{ children }
	&lt;/Head&gt;
  )
}
</code></pre>



<p class="wp-block-paragraph">And now we’ll create our index page, which serves as the landing page in a NextJs app. Notice that instead of using the Head component, we will import our dynamic SearchEngineHead implementation:</p>



<p class="wp-block-paragraph"><strong><em>index.js</em></strong></p>



<pre class="wp-block-code"><code>import SearchEngineHead from './components/SearchEngineHead.js';
import styles from '../styles/Home.module.css';
import globalMeta from './globalmeta';
import Link from 'next/link';
 
export default function Home() {
 
  const structuredLd = JSON.stringify({
    	"@context": globalMeta.canonicalUrl + "/cool-article",
    	"description": "NextJs Head, a reliable guide for how to use it and what it's really for."
  });
 
  return (
	&lt;div className={styles.container}&gt;
 
  	&lt;SearchEngineHead
    	canonicalUrl={ globalMeta.siteUrl }
    	structuredData={structuredLd}
    	title="NextJs Head"
    	description="NextJs Head, a reliable guide for how to use it and what it's really for."
    	ogType="website"
    	/&gt;
 
  	&lt;main className={styles.main}&gt;
    	&lt;div&gt;
        	&lt;h2&gt;Use NextJs Head!&lt;/h2&gt;
        	&lt;Link href="/coolarticle"&gt;Cool Article!&lt;/Link&gt;
    	&lt;/div&gt;
  	&lt;/main&gt;
	&lt;/div&gt;
  )
}
</code></pre>



<p class="wp-block-paragraph">And finally, we’ll simulate a blog article, which will also import our dynamic SearchEngineHead component:</p>



<p class="wp-block-paragraph"><strong><em>coolarticle.js</em></strong></p>



<pre class="wp-block-code"><code>import SearchEngineHead from './components/SearchEngineHead.js';
import styles from '../styles/Home.module.css';
import globalMeta from './globalmeta';
import Link from 'next/link';
 
export default function CoolArticle() {
 
  const structuredLd = JSON.stringify({
    	"@context": globalMeta.canonicalUrl + "/cool-article",
    	"description": "NextJs Head, a cool article page for our nextjs Head example site."
  });

 
  return (
	&lt;div className={styles.container}&gt;
 
  	&lt;SearchEngineHead
    	canonicalUrl={ globalMeta.siteUrl + "/cool-article" }
    	structuredData={structuredLd}
	    title="NextJs Head | Cool Article!"
    	description="NextJs Head, a cool article page for our nextjs Head example site."
    	ogType="article"
    	/&gt;
 
  	&lt;main className={styles.main}&gt;
    	&lt;div&gt;
        	&lt;h2&gt;Cool article!&lt;/h2&gt;
            &lt;Link href="/"&gt;Home&lt;/Link&gt;
    	&lt;/div&gt;
  	&lt;/main&gt;
	&lt;/div&gt;
  )
}
</code></pre>



<p class="wp-block-paragraph">And there we have it! A basic implementation of a dynamic Head component using NextJs.</p>



<p class="wp-block-paragraph">Let’s have a quick look at the important parts of the HTML output from the head tag on our article page:</p>



<p class="wp-block-paragraph"><strong><em>NextJs Head HTML Output</em></strong></p>



<pre class="wp-block-code"><code>&lt;head&gt;
  &lt;meta charSet="utf-8"/&gt;
  &lt;title&gt;NextJs Head | Cool Article!&lt;/title&gt;
  &lt;meta name="description" content="NextJs Head, a cool article     page for our nextjs Head example site."/&gt;
  &lt;link rel="canonical" href="https://yoursite.com/cool-article"/&gt;
  &lt;meta name="viewport" content="width=device-width,   initial-scale=1"/&gt;
  &lt;link rel="icon" href="/favicon.ico"/&gt;
  &lt;meta property="og:locale" content="en_US"/&gt;
  &lt;meta property="og:site_name" content="Your Site Name"/&gt;
  &lt;meta property="og:type" content="article"/&gt;
  &lt;meta property="og:description" content="NextJs Head, a cool article page for our nextjs Head example site."/&gt;
  &lt;meta property="og:image" content="https://yoursite.com/images/logo.png"/&gt;
  &lt;meta property="og:url" content="undefined/cool-article"/&gt;
 
  &lt;script type="application/ld+json"&gt;
    {
     "@context":"undefined/cool-article",
     "description":"NextJs Head, a cool article page for our nextjs Head example site."
    }
  &lt;/script&gt;
&lt;/head&gt;
</code></pre>



<p class="wp-block-paragraph">As can be seen from the output, we have successfully populated the head tag using NextJs Head dynamically. The benefits of this method are quite obvious.&nbsp;</p>



<p class="wp-block-paragraph">If you have a site with 100 pages, and you need to change something such as the canonical URL, you’d have to manually make the change on each page without our global data. As it stands, we can make our change one time versus one hundred times.&nbsp;</p>



<h2 class="wp-block-heading" id="overview-next-js-head">NextJs Head | Final Thoughts &amp; Quick Overview</h2>



<p class="wp-block-paragraph">When optimizing a site for search engines, the head tag contains important metadata that Google uses to index and rank your site. When using NextJs, the way to modify the head tag is by utilizing the Head component.</p>



<p class="wp-block-paragraph">The Head component comes with NextJs out of the box. It can be imported into any page component, or a custom implemented component, for modifying the HTML head tag.</p>



<p class="wp-block-paragraph">NextJs will automatically extract your content from the Head component, and inject it into the HTML head tag. This feature is imperative for optimizing metadata found within the head tag.</p>



<p class="wp-block-paragraph">For <a href="https://www.ohmycrawl.com/technical-seo/react/">optimizing SEO in React</a> style apps, some variant of NextJs Head must be used. If you plan on using NextJs or other ReactJs frameworks for your development, becoming familiar with this concept is a must.</p>
<p>The post <a href="https://www.ohmycrawl.com/nextjs/head/">NextJS Head: Optimize MetaData</a> appeared first on <a href="https://www.ohmycrawl.com">OhMyCrawl</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.ohmycrawl.com/nextjs/head/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Next JS Robots.txt</title>
		<link>https://www.ohmycrawl.com/nextjs/robots-txt-2/</link>
					<comments>https://www.ohmycrawl.com/nextjs/robots-txt-2/#respond</comments>
		
		<dc:creator><![CDATA[EditorOhMyCrawl]]></dc:creator>
		<pubDate>Sun, 11 Jun 2023 16:14:48 +0000</pubDate>
				<category><![CDATA[Next.js]]></category>
		<guid isPermaLink="false">https://www.ohmycrawl.com/?p=21069</guid>

					<description><![CDATA[<p>When developing a site with Next.js, it’s important to consider how your robots.txt file will be generated. Just like the sitemap and the metadata tags in the website, robots.txt file is an important factor when aiming for performant Next JS SEO optimization metrics, and NextJs offers some great tooling to facilitate the process of building ... <a title="Next JS Robots.txt" class="read-more" href="https://www.ohmycrawl.com/nextjs/robots-txt-2/" aria-label="More on Next JS Robots.txt">Read more</a></p>
<p>The post <a href="https://www.ohmycrawl.com/nextjs/robots-txt-2/">Next JS Robots.txt</a> appeared first on <a href="https://www.ohmycrawl.com">OhMyCrawl</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">When developing a site with <a href="https://www.ohmycrawl.com/nextjs/">Next.js</a>, it’s important to consider how your <a href="https://www.ohmycrawl.com/search-engine-optimization/robots-txt/">robots.txt</a> file will be generated. Just like the sitemap and the metadata tags in the website, robots.txt file is an important factor when aiming for performant Next JS SEO optimization metrics, and NextJs offers some great tooling to facilitate the process of building one.</p>



<div class="wp-block-columns has-background is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex" style="background-color:#fff4cf">
<div class="wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:33.33%"><div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><img decoding="async" width="313" height="280" src="https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs.jpg" alt="" class="wp-image-21460" style="aspect-ratio:1.1168831168831168;width:284px;height:auto" srcset="https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs.jpg 313w, https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs-300x268.jpg 300w" sizes="(max-width: 313px) 100vw, 313px" /><figcaption class="wp-element-caption"><em>SEO Consultant </em></figcaption></figure>
</div></div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:66.66%">
<p class="has-text-align-center has-large-font-size wp-block-paragraph">Free Weekly SEO Newsletter</p>



<p class="wp-block-paragraph">Hey! I&#8217;m Scott, I&#8217;ve been an SEO consultant for nearly 10 years. Get on my weekly newsletter to get..</p>



<ul class="wp-block-list">
<li>Weekly SEO updates, keep up with the latest and greatest.</li>



<li>How we grow websites from zero to millions of visitors</li>



<li>A bunch of SEO tips and Tricks you won&#8217;t find anywhere else test</li>
</ul>


<div class="gb-button-wrapper gb-button-wrapper-88826626">

<a class="gb-button gb-button-d3a6a344 gb-button-text" href="#cb717b282f"><strong>Get On The Newsletter</strong></a>

</div></div>
</div>



<h2 class="wp-block-heading">TL;DR: Quick Links</h2>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<ul class="wp-block-list">
<li><a href="#robots-overview-overview">Next JS Robots txt Quick Overview</a></li>



<li><a href="#robots-overview-looks">What robots.txt looks like</a></li>
</ul>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<ul class="wp-block-list">
<li><a href="#robots-overview-using">Using next-sitemap for your robots.txt file</a></li>



<li><a href="#robots-overview-configuring">Configuring Rules in Your robots.txt File With next-sitemap</a></li>
</ul>
</div>
</div>



<h2 class="wp-block-heading">What is the robots.txt file for?</h2>



<p class="wp-block-paragraph">When setting up <a href="https://www.ohmycrawl.com/nextjs/seo/">NextJS SEO optimization</a> to build your robots file, it’s important to understand what the robots file actually is and what it’s used for. In a nutshell, similar to <a href="https://www.ohmycrawl.com/nextjs/head/">metadata tags</a> the robots.txt file is used to tell search engine crawlers which pages they can access on your site.</p>



<p class="wp-block-paragraph">Many developers and SEO guys think this means you’re essentially telling the search engine it can’t index certain pages, but that’s not necessarily the case. To quote the <a href="https://developers.google.com/search/docs/advanced/robots/intro">Google documentation</a>: </p>



<p class="wp-block-paragraph"><strong><em>“[robots.txt] is not a mechanism for keeping a web page out of Google</em></strong><em>. To keep a web page out of Google, </em><a href="https://developers.google.com/search/docs/advanced/crawling/block-indexing"><em>block indexing with noindex</em></a><em> or password-protect the page.”</em></p>



<p class="wp-block-paragraph">Essentially, google can still see your page and index it, they just won’t crawl and retrieve data such as the meta description. For this reason, robots.txt is used mainly to limit crawler traffic on your site, in order to avoid potentially overloading your site with page requests.</p>



<h2 class="wp-block-heading" id="robots-overview-looks">What does the robots.txt look like?</h2>



<p class="wp-block-paragraph">The robots.txt file uses a standard known as the <em>robots exclusion protocol, </em>and the syntax is fairly simple to follow. A basic robots.txt file will look something like this:</p>



<pre class="wp-block-code"><code>User-agent: Googlebot

Disallow: /nocrawl/

User-agent: *

Allow: /

Sitemap: http://www.yoursite.com/sitemap.xml</code></pre>



<p class="wp-block-paragraph">The robots.txt file is broken up into rules. This particular example reflects to rules:</p>



<ul class="wp-block-list">
<li><strong>Rule 1: </strong>Disallow Googlebot from crawling anything within the /nocrawl directory.</li>



<li><strong>Rule 2: </strong>All other user agents can crawl the entire site.</li>
</ul>



<p class="wp-block-paragraph">It’s important to note that if rule 2 were omitted, the result would be the same. The behavior of the robots standard defaults to allowing all user agents to crawl the site in question.&nbsp;&nbsp;&nbsp; The options for rules are fairly extensive. If you’re interested in taking a closer look, head on over to the <a href="https://developers.google.com/search/docs/advanced/robots/create-robots-txt#create_rules">Google docs</a> for a more extensive guide.</p>



<h2 class="wp-block-heading">Where does robots.txt go in a NextJs project?</h2>



<p class="wp-block-paragraph">For any search engine to be able to access the robots file, it must be located at the root directory of the site. NextJs projects have a <strong>/public </strong>directory that is used to serve out static files from your site, and this directory represents the root of your project.</p>



<p class="wp-block-paragraph">This means that you should always put the robots.txt file in the <strong>/public </strong>directory of your NextJs project. This will result in your robots file being served out in the proper location at https://mysite.com/robots.txt</p>



<p class="wp-block-paragraph">It can be tedious remembering to include the robots file on each build, which is why when doing <a href="https://www.ohmycrawl.com/nextjs/seo/">SEO with NextJS</a> many opt for using the next-sitemap module to automate the process of generating and configuring your robots file.</p>



<h2 class="wp-block-heading" id="robots-overview-using">Using next-sitemap for your robots.txt file</h2>



<p class="wp-block-paragraph">As the name implies, next-sitemap is a module that handles the creation and maintenance of sitemap files. However, this package also has the ability to generate robots.txt files as well.&nbsp;</p>



<p class="wp-block-paragraph">Setting up a <a href="https://www.ohmycrawl.com/nextjs/sitemap/">next-sitemap</a> is fairly simple. Once your NextJs project is up and running, run the following command to install next-sitemap:</p>



<pre class="wp-block-code"><code>npm i next-sitemap</code></pre>



<p class="wp-block-paragraph">Now, set up your configuration file to include the generation of a robots.txt file. At the root of your project, create a file called <strong>next-sitemap.config.js</strong> and add the following code:</p>



<pre class="wp-block-code"><code>const config = {
    siteUrl: 'https://yoursite.com',
    generateRobotsTxt: true, // (Parameter for creating robots.txt file)
  }
 
module.exports = config;</code></pre>



<p class="wp-block-paragraph">Next you can simply build your project and run the next-sitemap script like so:</p>



<pre class="wp-block-code"><code>npm run build</code></pre>



<p class="wp-block-paragraph">And..</p>



<pre class="wp-block-code"><code>npm run next-sitemap</code></pre>



<p class="wp-block-paragraph">And that’s it! You should now have a generated robots.txt file in your public directory.</p>



<h2 class="wp-block-heading" id="robots-overview-configuring">Configuring Rules in Your robots.txt File With next-sitemap</h2>



<p class="wp-block-paragraph">Creating the robots file was easy with next-sitemap, but that’s not very useful if we can’t add some rules along with it. To create rules within our robots file, we can modify our next-sitemap config file to include the <strong>robotsTxtOptions </strong>and <strong>policies </strong>properties.</p>



<p class="wp-block-paragraph">A next-sitemap file that adds a rule for disallowing all user agents from crawling a specific directory looks like this:</p>



<pre class="wp-block-code"><code>const config = {
    siteUrl: 'https://yoursite.com',
    generateRobotsTxt: true, 
    robotsTxtOptions: {
        policies: &#91;
                   { userAgent: "*", disallow:"/nocrawling"},
          ]
    }
  }
 
module.exports = config;</code></pre>



<p class="wp-block-paragraph">Just remember, when using this method the policy objects within the array equate to individual rules in the robots file. Pretty simple!</p>



<h2 class="wp-block-heading" id="robots-overview-overview">NextJs robots.txt | Overview and Conclusion</h2>



<p class="wp-block-paragraph">Creating a robots.txt file within your web app is as simple as adding the robots file to the <strong>/public </strong>directory, adding some rules, and building your project. The key here is understanding what the robots file is for, and how you should configure it for your particular needs.</p>



<p class="wp-block-paragraph">Utilizing the next-sitemap module can help streamline the process of creating a robots file. The next-sitemap module accommodates the programmatic generation of the robots file, which allows developers the flexibility to automate the process of keeping this file up to date.</p>



<p class="wp-block-paragraph">Overall, just like many aspects of development, NextJs makes this task simple and straightforward. Whether you opt for the manual or automated method, hopefully you can now feel confident when using NextJs to create your robots file.</p>
<p>The post <a href="https://www.ohmycrawl.com/nextjs/robots-txt-2/">Next JS Robots.txt</a> appeared first on <a href="https://www.ohmycrawl.com">OhMyCrawl</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.ohmycrawl.com/nextjs/robots-txt-2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Next.js Site map</title>
		<link>https://www.ohmycrawl.com/nextjs/sitemap/</link>
					<comments>https://www.ohmycrawl.com/nextjs/sitemap/#respond</comments>
		
		<dc:creator><![CDATA[EditorOhMyCrawl]]></dc:creator>
		<pubDate>Sun, 11 Jun 2023 16:13:13 +0000</pubDate>
				<category><![CDATA[Next.js]]></category>
		<guid isPermaLink="false">https://www.ohmycrawl.com/?p=21059</guid>

					<description><![CDATA[<p>Next js sitemap is a pretty simple concept. In a nutshell, a Site map is a file that contains a data representation of each page within your website, along with any other content deemed important enough to specify to search engines such as Google. Next.js makes this very easy to implement. Sitemap entries can include, ... <a title="Next.js Site map" class="read-more" href="https://www.ohmycrawl.com/nextjs/sitemap/" aria-label="More on Next.js Site map">Read more</a></p>
<p>The post <a href="https://www.ohmycrawl.com/nextjs/sitemap/">Next.js Site map</a> appeared first on <a href="https://www.ohmycrawl.com">OhMyCrawl</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Next js sitemap is a pretty simple concept. In a nutshell, a <a href="https://en.wikipedia.org/wiki/Site_map">Site map</a> is a file that contains a data representation of each page within your website, along with any other content deemed important enough to specify to search engines such as Google. <a href="https://www.ohmycrawl.com/nextjs/">Next.js</a> makes this very easy to implement.</p>



<p class="wp-block-paragraph">Sitemap entries can include, but are not limited to, videos, <a href="https://www.ohmycrawl.com/nextjs/image-optimization/">images</a>, PDFs, and of course the web pages themselves. The most common format for a sitemap file is XML, and although Google supports other formats such RSS and Text, we&#8217;ll be focusing on the XML format due to its prevalent usage.</p>



<div class="wp-block-columns has-background is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex" style="background-color:#fff4cf">
<div class="wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:33.33%"><div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><img decoding="async" width="313" height="280" src="https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs.jpg" alt="" class="wp-image-21460" style="aspect-ratio:1.1168831168831168;width:284px;height:auto" srcset="https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs.jpg 313w, https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs-300x268.jpg 300w" sizes="(max-width: 313px) 100vw, 313px" /><figcaption class="wp-element-caption"><em>SEO Consultant </em></figcaption></figure>
</div></div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:66.66%">
<p class="has-text-align-center has-large-font-size wp-block-paragraph">Free Weekly SEO Newsletter</p>



<p class="wp-block-paragraph">Hey! I&#8217;m Scott, I&#8217;ve been an SEO consultant for nearly 10 years. Get on my weekly newsletter to get..</p>



<ul class="wp-block-list">
<li>Weekly SEO updates, keep up with the latest and greatest.</li>



<li>How we grow websites from zero to millions of visitors</li>



<li>A bunch of SEO tips and Tricks you won&#8217;t find anywhere else test</li>
</ul>


<div class="gb-button-wrapper gb-button-wrapper-88826626">

<a class="gb-button gb-button-d3a6a344 gb-button-text" href="#cb717b282f"><strong>Get On The Newsletter</strong></a>

</div></div>
</div>



<h2 class="wp-block-heading">TL;DR: Quick Links</h2>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<ul class="wp-block-list">
<li><a href="#sitemap-next-sitemap-overview">NextJs and next-sitemap Quick Overview</a></li>



<li><a href="#sitemap-next-sitemap-generating">Generating sitemap.xml Files</a></li>



<li><a href="#sitemap-next-sitemap-dynamic">Dynamic Sitemaps</a></li>
</ul>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<ul class="wp-block-list">
<li><a href="#sitemap-next-sitemap-building">Building a Custom sitemap Generator</a></li>



<li><a href="#sitemap-next-sitemap-how">How next-sitemap Creates Dynamic Sitemaps</a></li>
</ul>
</div>
</div>



<h2 class="wp-block-heading">Sitemap Maintenance | Keeping URLs up to Date</h2>



<p class="wp-block-paragraph">Maintaining a sitemap manually can be a very tedious endeavor. Every time a new page or piece of content is added to a site, or a URL changes, the sitemap file must be updated as well. This can become unmanageable, especially when maintaining medium to large sized sites.</p>



<p class="wp-block-paragraph">For this reason, frameworks usually offer some tooling to facilitate the task of maintaining sitemaps. Usually, this comes in the form of a sitemap generator, which allows the developer or maintainer to generate sitemaps automatically, or generate them as needed when updates are made.</p>



<div class="wp-block-columns has-background is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex" style="background-color:#fff4cf">
<div class="wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:33.33%"><div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><img loading="lazy" decoding="async" width="313" height="280" src="https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs.jpg" alt="" class="wp-image-21460" style="width:258px;height:231px" srcset="https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs.jpg 313w, https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs-300x268.jpg 300w" sizes="auto, (max-width: 313px) 100vw, 313px" /><figcaption class="wp-element-caption"><em>Javascript SEO Consultant </em></figcaption></figure>
</div></div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:66.66%">
<p class="has-text-align-center has-large-font-size wp-block-paragraph">Free Next JS SEO Training</p>



<p class="wp-block-paragraph">Hey! I&#8217;m Scott, I&#8217;ve been working on Javascript &amp; highly technical websites for nearly 10 years.  Opt-in for my free training and get&#8230;</p>



<ul class="wp-block-list">
<li>Learn how to troubleshoot Next JS SEO &amp; crawl issues</li>



<li>How we grow websites from zero to millions of visitors</li>



<li>A bunch of Javascrpt SEO tips and Tricks you won&#8217;t find anywhere else test</li>
</ul>


<div class="gb-button-wrapper gb-button-wrapper-88826626">

<a class="gb-button gb-button-d3a6a344 gb-button-text" href="#cbe94c6c08"><strong>Get The Training</strong></a>

</div></div>
</div>



<h2 class="wp-block-heading">NextJs | Sitemap Generator vs Dynamic Sitemap</h2>



<p class="wp-block-paragraph">The difference between these two techniques is subtle but important to understand. Each technique may or may not be optimal for <a href="https://www.ohmycrawl.com/nextjs/seo/">Next SEO</a> depending on your particular situation.</p>



<p class="wp-block-paragraph">Using NextJs, a sitemap generator creates an actual sitemap file to be served out from the /public directory as a static file.</p>



<p class="wp-block-paragraph">In contrast, a dynamic sitemap uses a page component to generate an object containing the sitemap schema on the fly, and attaches it to the response body. In essence, a NextJs component is used to mimic an actual sitemap file.</p>



<h2 class="wp-block-heading">next-sitemap | Capable for Both Occasions</h2>



<p class="wp-block-paragraph">The next-sitemap module comes equipped to act as either a sitemap generator, or as a tool for building dynamic sitemaps. Later on, we’re going to look under the hood at how this works. But first, let’s look at a simple implementation with next-sitemap.</p>



<h3 class="wp-block-heading" id="sitemap-next-sitemap-generating">Generating sitemap.xml Files With next-sitemap</h3>



<p class="wp-block-paragraph">Once you have a NextJs project up and running, go ahead and install next-sitemap with the following command:</p>



<pre class="wp-block-code"><code>npm i next-sitemap</code></pre>



<p class="wp-block-paragraph">The next-sitemap module requires a configuration file. So, in the root of your project, create a file called <strong>next-sitemap.config.js </strong>and add the following code:</p>



<pre class="wp-block-code"><code>const config = {
    siteUrl: 'https://yoursite.com',
    generateRobotsTxt: true, // (Optional parameter for creating <a href="https://www.ohmycrawl.com/nextjs/robots-txt-2/">robots.txt</a> file)
    // Other available options..
  }
 
module.exports = config;</code></pre>



<p class="wp-block-paragraph"><span style="text-decoration: underline;">With our module installed and configuration file in place, let’s go ahead and run a build on our project.</span></p>



<pre class="wp-block-code"><code>npm run build</code></pre>



<p class="wp-block-paragraph">The NextJs docs recommend adding a `postscript` to the package.json file. So, let’s go ahead and follow their lead by adding this code to package.json:</p>



<pre class="wp-block-code"><code>"postbuild": "next-sitemap"</code></pre>



<p class="wp-block-paragraph">Now, we’re ready to build our sitemaps! Run the following command, and let’s check out what happens:</p>



<pre class="wp-block-code"><code>npm run postbuild</code></pre>



<p class="wp-block-paragraph">Assuming this command executed without error, you should see some output indicating that your two sitemap files have been built: sitemap.xml and sitemap-0.xml</p>



<p class="wp-block-paragraph">But why two sitemaps? sitemap.xml acts as a reference to all other sitemaps, this way if you have a website with lots of pages (in the thousands if not millions), you can break up your sitemaps into multiple smaller files, which load and can be crawled more efficiently.</p>



<p class="wp-block-paragraph">Here’s a look inside the sitemap.xml that we just generated:</p>



<pre class="wp-block-code"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"&gt;
        &lt;sitemap&gt;
                &lt;loc&gt;https://example.com/sitemap-0.xml&lt;/loc&gt;
        &lt;/sitemap&gt;
&lt;/sitemapindex&gt;</code></pre>



<p class="wp-block-paragraph">As you can see, this file simply references the sitemap-0.xml file, which contains our actual pages. Search engines will readily crawl this sitemap configuration, and on modern websites this method of breaking up sitemaps into multiple files is quite common.</p>



<h3 class="wp-block-heading" id="sitemap-next-sitemap-dynamic">Dynamic Sitemaps With next-sitemap</h3>



<div class="wp-block-columns has-background is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex" style="background-color:#fff4cf">
<div class="wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:33.33%"><div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><img loading="lazy" decoding="async" width="313" height="280" src="https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs.jpg" alt="" class="wp-image-21460" style="width:258px;height:231px" srcset="https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs.jpg 313w, https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs-300x268.jpg 300w" sizes="auto, (max-width: 313px) 100vw, 313px" /><figcaption class="wp-element-caption"><em>Javascript SEO Consultant </em></figcaption></figure>
</div></div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:66.66%">
<p class="has-text-align-center has-large-font-size wp-block-paragraph">Free Next JS SEO Training</p>



<p class="wp-block-paragraph">Hey! I&#8217;m Scott, I&#8217;ve been working on Javascript &amp; highly technical websites for nearly 10 years.  Opt-in for my free training and get&#8230;</p>



<ul class="wp-block-list">
<li>Learn how to troubleshoot Next JS SEO &amp; crawl issues</li>



<li>How we grow websites from zero to millions of visitors</li>



<li>A bunch of Javascrpt SEO tips and Tricks you won&#8217;t find anywhere else test</li>
</ul>


<div class="gb-button-wrapper gb-button-wrapper-88826626">

<a class="gb-button gb-button-d3a6a344 gb-button-text" href="#cbe94c6c08"><strong>Get The Training</strong></a>

</div></div>
</div>



<p class="wp-block-paragraph">Using next-sitemap for dynamic sitemaps isn’t quite as simple as generating sitemap files, but the process is still fairly streamlined. Basically, all pages in a NextJs site are served out in the /pages directory. So, we’ll create a sitemap page component that “acts” like a sitemap.xml file.</p>



<p class="wp-block-paragraph">We need to import the `getServerSideSitemap` method from the next-sitemap module, and build a page component that doesn’t return any JSX. Instead, the page component will run some code inside the `getServerSideProps` method.</p>



<p class="wp-block-paragraph">Here’s a look at a basic sitemap component that can accomplish this:</p>



<pre class="wp-block-code"><code>import { getServerSideSitemap } from 'next-sitemap';
 
function GenSitemap() {
}
 
export async function getServerSideProps({ ctx }) {

// We could place code here that fetches pages from a CMS to build a dynamic sitemap.
  return getServerSideSitemap(ctx, &#91;
    {
      loc: 'https://example.com',
      lastmod: new Date().toISOString(),
      changefreq: “monthly”,
      priority: “1”
    },
    {
      loc: 'https://example.com/dynamic-path-2',
      lastmod: new Date().toISOString(),
      changefreq: “monthly”,
      priority: “1”
    },
  ])
 
}
 
export default GenSitemap;</code></pre>



<p class="wp-block-paragraph">As can be seen in the above code, we return our imported `getServerSideSitemap` method from `getServerSideProps`, and pass it an array containing all the data related to building our sitemap.</p>



<p class="wp-block-paragraph">And that’s it, next-sitemap handles the rest behind the scenes!</p>



<h2 class="wp-block-heading" id="sitemap-next-sitemap-building">Building a Custom sitemap Generator with NextJs</h2>



<p class="wp-block-paragraph">The process of building your sitemap files is abstracted by the next-sitemap module. This makes implementing sitemaps with NextJs a fairly simple process.</p>



<p class="wp-block-paragraph">However, it’s a good idea to understand how things operate, so let’s look at a basic example of how we can generate sitemap files by leveraging the NodeJs platform that lives underneath the Next framework.</p>



<h3 class="wp-block-heading">The Typical sitemap Schema</h3>



<p class="wp-block-paragraph">Our goal here is to generate a <strong>sitemap.xml</strong> file. So, what’s a sitemap file look like? A typical schema for a sitemap xml file will look something like this:</p>



<pre class="wp-block-code"><code>&lt;url&gt;

    &lt;loc&gt;http://example.com/blog&lt;/loc&gt;
    &lt;lastmod&gt;date created&lt;/lastmod&gt;
    &lt;changefreq&gt;weekly&lt;/changefreq&gt;
    &lt;priority&gt;1.0&lt;/priority&gt;

&lt;/url&gt;</code></pre>



<p class="wp-block-paragraph">Let’s see how we can create a file containing this schema using some back-end Javascript code while tweaking the webpack configuration.</p>



<h3 class="wp-block-heading">Modifying the NextJs Config file to Run the sitemap Script</h3>



<p class="wp-block-paragraph">NextJs uses webpack to bundle up and/or require modules, which we can tap into using our NextJs configuration file. Let’s modify the NextJs config file to require a script that builds a sitemap file each time it runs on the server. We can modify our `next.config.js` like so:</p>



<pre class="wp-block-code"><code>module.exports = {
...
  webpack: (config, { isServer }) =&gt; {
    if (isServer) {
      require("./server-scripts/sitemap-generator");
    }
    return config;
  },
};</code></pre>



<p class="wp-block-paragraph">Webpack runs twice, once on the server and once on the client. The `isServer` parameter allows us to only run a script when webpack is running on the server. Therefore, our sitemap-generator script will run each time our scripts are bundled during a request.</p>



<h3 class="wp-block-heading">Creating a NextJs Server-Side sitemap Script</h3>



<p class="wp-block-paragraph">Utilizing NextJs on the server allows us to use features within NodeJs, such as the native `fs` module used for modifying the file system. Using the `fs` module, we can traverse the /pages directory, and generate a sitemap file based on its contents. A basic example could look something like this:</p>



<p class="wp-block-paragraph"><strong>sitemap-generator.js</strong></p>



<pre class="wp-block-code"><code>const fs = require('fs');

function genSiteMap() {
            const files = fs.readdirSync(‘/pages’);
             const url = process.env.WEBSITE_URL;
 
             let sitemap = `&lt;urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"&gt;`;
             for (var i = 0; i &lt; files.length; i++) {
                    let fileName = files&#91;i]);
                    let formattedFileName = fileName.replace(/\.&#91;^/.]+$/, "");
                    sitemap = sitemap + `&lt;loc&gt;${url}${formattedFileName}&lt;/loc&gt;` +
                                                         `&lt;lastmod&gt;${new Date().toISOString()
&lt;/lastmod&gt;` +
                                                         ‘&lt;changefreq&gt;weekly&lt;/changefreq&gt;’ +
                                                         ‘&lt;priority&gt;1.0&lt;/priority&gt;’;
             };
             sitemap = sitemap + ‘&lt;/urlset&gt;`
             fs.writeFileSync('public/sitemap.xml', sitemap)
}

genSiteMap();</code></pre>



<p class="wp-block-paragraph">This example code will iterate over all files in the /pages, and populate a variable formatted with all of the necessary schema for our sitemap.xml file. We then use this variable as a parameter with the `writeFileSync` method to create the actual file itself, and place it in the /public directory so NextJs will serve this out as a static file.</p>



<p class="wp-block-paragraph">This code is very much barebones, but it serves as a good example for understanding how to leverage NodeJs functionality within NextJs to create sitemap files on the fly.</p>



<h2 class="wp-block-heading" id="sitemap-next-sitemap-how">How Does next-sitemap Create Dynamic Sitemaps?</h2>



<div class="wp-block-columns has-background is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex" style="background-color:#fff4cf">
<div class="wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:33.33%"><div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><img loading="lazy" decoding="async" width="313" height="280" src="https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs.jpg" alt="" class="wp-image-21460" style="width:258px;height:231px" srcset="https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs.jpg 313w, https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs-300x268.jpg 300w" sizes="auto, (max-width: 313px) 100vw, 313px" /><figcaption class="wp-element-caption"><em>Javascript SEO Consultant </em></figcaption></figure>
</div></div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:66.66%">
<p class="has-text-align-center has-large-font-size wp-block-paragraph">Free Next JS SEO Training</p>



<p class="wp-block-paragraph">Hey! I&#8217;m Scott, I&#8217;ve been working on Javascript &amp; highly technical websites for nearly 10 years.  Opt-in for my free training and get&#8230;</p>



<ul class="wp-block-list">
<li>Learn how to troubleshoot Next JS SEO &amp; crawl issues</li>



<li>How we grow websites from zero to millions of visitors</li>



<li>A bunch of Javascrpt SEO tips and Tricks you won&#8217;t find anywhere else test</li>
</ul>


<div class="gb-button-wrapper gb-button-wrapper-88826626">

<a class="gb-button gb-button-d3a6a344 gb-button-text" href="#cbe94c6c08"><strong>Get The Training</strong></a>

</div></div>
</div>



<p class="wp-block-paragraph">Without getting too in depth, it’s worth taking a look at how next-sitemap is able to generate these dynamic sitemaps from a regular NextJs page component. The answer lies in the fact that NextJs can render components on the server, which means we can hijack some NodeJs functionality.</p>



<p class="wp-block-paragraph">Every request made to a site built on the NodeJs platform requires Node to build a response object. This response object can be modified as needed, and this is what next-sitemap uses to inject our sitemap data into the response body.</p>



<p class="wp-block-paragraph">Here’s a basic look at how the response object can be modified within a NextJs component:</p>



<pre class="wp-block-code"><code>function GenSitemap() {
}
 
export async function getServerSideProps({ res }) {
            // Code to build sitemap content would go here.
            const sitemapContent = MethodToBuildSitemap();
            res.setHeader('Content-Type', 'text/xml');
             res.write(sitemapContent);
 
             res.end();
 
            return {
                        props: {}
            }
}</code></pre>



<p class="wp-block-paragraph">As you can see, we were able to simply pass the response object into the `getServerSideProps` method, then write some sitemap data to the response body. Cool, now whenever this page is requested, a dynamic sitemap could be built on the fly.</p>



<h2 class="wp-block-heading" id="sitemap-next-sitemap-overview">NextJs and next-sitemap | Overview and Concluding Thoughts</h2>



<p class="wp-block-paragraph">NextJs can be used to generate sitemap files, or create dynamic sitemaps that render each time a page component is requested. The next-sitemap module was built to streamline this process, and can be included in any NextJs app using your preferred package manager.</p>



<p class="wp-block-paragraph">Although using next-sitemap abstracts away much of the technical difficulty in creating sitemaps for your Next app, it’s still a good idea to understand how the process works under the hood. For this reason, we took a quick glance at how NextJs is able to accomplish each form of sitemap creation.</p>



<p class="wp-block-paragraph">If you’re interested in creating performant SEO with the NextJs framework, having a good handle on your sitemap situation is a must. This article was created to offer guidance and understanding in this area, and we highly recommend creating a NextJs app and trying it out yourself.</p>
<p>The post <a href="https://www.ohmycrawl.com/nextjs/sitemap/">Next.js Site map</a> appeared first on <a href="https://www.ohmycrawl.com">OhMyCrawl</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.ohmycrawl.com/nextjs/sitemap/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Next JS SEO</title>
		<link>https://www.ohmycrawl.com/nextjs/seo/</link>
					<comments>https://www.ohmycrawl.com/nextjs/seo/#respond</comments>
		
		<dc:creator><![CDATA[EditorOhMyCrawl]]></dc:creator>
		<pubDate>Sun, 11 Jun 2023 16:12:45 +0000</pubDate>
				<category><![CDATA[Next.js]]></category>
		<category><![CDATA[React]]></category>
		<guid isPermaLink="false">https://www.ohmycrawl.com/?p=21136</guid>

					<description><![CDATA[<p>Next.Js is an open source framework built on top of React that is often leveraged for Search Engine Optimization purposes. React is a framework used primarily for building front-end user interfaces in the form of single page applications (SPAs). SPAs were a great improvement on user experience (UX), and in many cases developer experience as ... <a title="Next JS SEO" class="read-more" href="https://www.ohmycrawl.com/nextjs/seo/" aria-label="More on Next JS SEO">Read more</a></p>
<p>The post <a href="https://www.ohmycrawl.com/nextjs/seo/">Next JS SEO</a> appeared first on <a href="https://www.ohmycrawl.com">OhMyCrawl</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph"><a href="https://www.ohmycrawl.com/nextjs/">Next.Js</a> is an open source framework built on top of React that is often leveraged for <a href="https://www.ohmycrawl.com/search-engine-optimization/">Search Engine Optimization</a> purposes. React is a framework used primarily for building front-end user interfaces in the form of single page applications (SPAs). SPAs were a great improvement on user experience (UX), and in many cases developer experience as well.&nbsp;</p>



<p class="wp-block-paragraph">React offers the flexibility of handling DOM rendering, routing, and state management all on the client. The declarative and intuitive tooling of React is popular among devs, and users were in turn presented with websites and web pages that felt more fluid, interactive, attention grabbing and dynamic. That&#8217;s great news! So what&#8217;s the problem? Well, the issues that arise from the React SPA model are multifaceted, and mostly related to <a href="https://www.ohmycrawl.com/technical-seo/spa/">SPA SEO</a> and google search. Rather than attempting to squash an explanation into a tiny intro paragraph, let&#8217;s take a closer look at the details of search engine optimization within a single-page application, and how NextJs addresses each search engine problem in turn.</p>



<div class="wp-block-columns has-background is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex" style="background-color:#fff4cf">
<div class="wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:33.33%"><div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><img loading="lazy" decoding="async" width="313" height="280" src="https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs.jpg" alt="" class="wp-image-21460" style="aspect-ratio:1.1168831168831168;width:284px;height:auto" srcset="https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs.jpg 313w, https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs-300x268.jpg 300w" sizes="auto, (max-width: 313px) 100vw, 313px" /><figcaption class="wp-element-caption"><em>SEO Consultant </em></figcaption></figure>
</div></div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:66.66%">
<p class="has-text-align-center has-large-font-size wp-block-paragraph">Free Weekly SEO Newsletter</p>



<p class="wp-block-paragraph">Hey! I&#8217;m Scott, I&#8217;ve been an SEO consultant for nearly 10 years. Get on my weekly newsletter to get..</p>



<ul class="wp-block-list">
<li>Weekly SEO updates, keep up with the latest and greatest.</li>



<li>How we grow websites from zero to millions of visitors</li>



<li>A bunch of SEO tips and Tricks you won&#8217;t find anywhere else test</li>
</ul>


<div class="gb-button-wrapper gb-button-wrapper-88826626">

<a class="gb-button gb-button-d3a6a344 gb-button-text" href="#cb717b282f"><strong>Get On The Newsletter</strong></a>

</div></div>
</div>



<h2 class="wp-block-heading">TL;DR: Next JS SEO Optimization &amp; Quick Links</h2>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<ul class="wp-block-list">
<li><a href="#next-seo-common-problems">Common SEO Related Problems with Next JS</a></li>



<li><a href="#next-seo-solutions">Solutions to Common SEO Related Problems with Next JS</a></li>



<li><a href="#next-seo-ssg">What is SSG</a></li>



<li><a href="#next-seo-ssr">What is SSR</a></li>
</ul>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<ul class="wp-block-list">
<li><a href="#next-seo-combining-ssg-ssr">Combining SSG and SSR</a></li>



<li><a href="#next-seo-image-optimization">NextJs Image Optimization</a></li>



<li><a href="#next-seo-handling-metadata">Handling Metadata in NextJs</a></li>



<li><a href="#next-seo-overview-conclusion">Next JS SEO</a> <a href="#next-seo-overview-conclusion">Overview &amp; Conclusion</a></li>
</ul>
</div>
</div>



<h2 class="wp-block-heading">How NextJs Improves SEO for React SPAs</h2>



<p class="wp-block-paragraph">The following is a summary of common search related issues that arise with <a href="https://www.ohmycrawl.com/technical-seo/react/">SEO for React SPAs</a>, followed by the associated solutions offered by the NextJs framework.</p>



<h3 class="wp-block-heading" id="next-seo-common-problems">React SPA | Overview of SEO Related Problems</h3>



<h4 class="wp-block-heading">Empty HTML Shell at Initial Page Load.</h4>



<p class="wp-block-paragraph">On the client, React works by injecting Javascript into an otherwise empty HTML page. This means that when the client requests a page, let&#8217;s say a homepage, that&#8217;s all they get; a blank canvas. After the blank canvas arrives, only then is the Javascript file(s) requested and sent to the client, which &#8216;paints&#8217; your empty canvas with the rest of the content that makes up the page.</p>



<h4 class="wp-block-heading">Bloated Javascript Files</h4>



<p class="wp-block-paragraph">The Javascript files needed to load the SPA are typically large and cumbersome files due to the complex nature of essentially building an entire website from code. Developers have made great progress optimizing these bundles, but the inherent nature of the issue makes it a tough optimization problem, especially in the context of search engine optimization. Simply put, there&#8217;s just too much going on and the bundlers can only shrink files so much.</p>



<h4 class="wp-block-heading">Slow Initial Page Load</h4>



<p class="wp-block-paragraph">The previous issue of bloated Javascript files results in slow page loads, which amounts to quite a few poor SEO metrics. Important speed measurements such as first contentful paint (FCP) and largest contentful paint (LCP) suffer, as will your Google rank.</p>



<h4 class="wp-block-heading">Poor Crawlability</h4>



<p class="wp-block-paragraph">When content isn’t presented fast, the result is a website that simply cannot be crawled efficiently by Googlebot crawlers. Google has improved its crawling software in recent years, allowing it to wait on the Javascript to finish loading before initiating the crawl sequence. However, these changes have proven to be unreliable in practice, resulting in long delays in indexing new content on most SPA websites and poor search engine optimization.</p>



<p class="wp-block-paragraph">Also, it&#8217;s important to remember that other smaller search engines haven&#8217;t even begun tackling the problem of waiting for large Javascript files to populate the DOM, compounding the issue of accessibility, crawlability and indexing even further.</p>



<h2 class="wp-block-heading" id="next-seo-solutions">NextJs | Overview of SEO Related Solutions</h2>



<h3 class="wp-block-heading">No More Empty HTML Shells</h3>



<p class="wp-block-paragraph">NextJs doesn&#8217;t send an empty HTML shell for the initial load. Instead, a combination of other techniques are used to ensure that content is always served at initial load, resulting in faster first contentful paint and other important SEO related metrics.</p>



<h3 class="wp-block-heading">Option for Either SSG or SSR</h3>



<p class="wp-block-paragraph">Static site generation (SSG) and <a href="https://www.ohmycrawl.com/nextjs/server-side-rendering-2/">server side rendering</a> (SSR) are combined to create high performance applications that still benefit from React tooling and the intuitive workflow developers have come to know and love.</p>



<h3 class="wp-block-heading">Ability to Dynamically Import Components</h3>



<p class="wp-block-paragraph">When a website loads, all aspects of the page aren&#8217;t needed at once. NextJs leverages React to allow devs to dynamically load components on demand, allowing for the prioritization of content.</p>



<h3 class="wp-block-heading">Built-in Image Optimization</h3>



<p class="wp-block-paragraph">A key web metric related to SEO is image size and quality. For improved search engine optimization, NextJs comes with an Image component that handles most image optimization issues for you, resizing and compressing images that are tailored for a preset group of screen sizes.</p>



<h3 class="wp-block-heading">Enhanced Crawlability</h3>



<p class="wp-block-paragraph">Because NextJs always serves content fast, and never a blank canvas, Googlebot can happily crawl Next apps quick and easy. This results in fast indexing of content and better Google rank which means better search engine optimization.</p>



<h2 class="wp-block-heading">Rendering for Every Occasion | SSG and SSR</h2>



<p class="wp-block-paragraph">Static site generation (SSG) and server side rendering (SSR) are the two pillars of NextJs. Let&#8217;s take a look at each and what they bring to the table as relates to optimal SEO performance.</p>



<h3 class="wp-block-heading" id="next-seo-ssg">What is SSG?</h3>



<p class="wp-block-paragraph">One could argue that the concept behind SSG goes all the way back to the inception of the internet itself. In the beginning, there were static HTML pages grouped in a hierarchy on the back-end. No fancy Javascript or CSS, no AJAX calls, just barebones HTML files that were served to the client.</p>



<p class="wp-block-paragraph">This is static at the extreme, and doesn&#8217;t <em>exactly </em>apply to our more modern SSG conceptual model. However, the comparison is valid and can help understand why static site generation exists in the first place.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph"><strong><em>SSG refers to a process of website creation in which each webpage HTML file is generated at build time, rather than on a per request basis.</em></strong></p>
</blockquote>



<p class="wp-block-paragraph">Builds can be triggered by the developer after making changes, or by hooks after a new piece of content is added to a linked CMS.</p>



<h4 class="wp-block-heading">SSG Example</h4>



<p class="wp-block-paragraph">As an example, let&#8217;s say you own a blog built with NextJs and a headless content management system (CMS). When you add a blog post to the CMS, your website now has access to that new data.&nbsp;</p>



<p class="wp-block-paragraph">With an SSG implementation, a <em>build command </em>is executed after the article is saved, which creates an actual HTML file injected with the data from your saved blog post.</p>



<p class="wp-block-paragraph">This static file is now ready to be served, either via a single server or via a CDN such as cloudflare, with no extra work to be done when a client requests it. It&#8217;s a fully completed HTML file, sitting there ready to go with all your content already inside.&nbsp;As you can imagine, this is highly effective for improving crawlability and overall SEO metrics. The content is <em>just there.</em></p>



<h4 class="wp-block-heading">SSG isn&#8217;t the End All be All</h4>



<p class="wp-block-paragraph">Although this technique is great for search engine optimization in less complex sites like blogs, it&#8217;s not so great for sites that rely heavily on a constantly changing data collection. Picture Twitter implemented with SSG; the website would constantly be generating static pages for every new Tweet!</p>



<p class="wp-block-paragraph">SSG isn&#8217;t great for dynamic data, which is why NextJs also offers SSR.</p>



<h3 class="wp-block-heading" id="next-seo-ssr">What is SSR?</h3>



<p class="wp-block-paragraph">The history of SSR doesn&#8217;t quite go back to the web&#8217;s inception, but it has had an interesting evolution nonetheless. After static pages became boring and databases entered the scene, server side rendering allowed developers to create sites dynamically, injecting saved data from databases to help create a more user defined experience.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph"><strong>SSR refers to a process of website creation in which each webpage HTML file is generated on the server, real-time on a per request basis.</strong></p>
</blockquote>



<p class="wp-block-paragraph">As an example, let&#8217;s again consider Twitter. When you login to your Twitter account, a request is made to the server. The server identifies who you are, retrieves content from the database relating to your account, and populates the page with all of the user-related Tweets and other content.</p>



<p class="wp-block-paragraph">When compared with a client side SPA, SSR offers flexibility by offering the option to serve some content immediately, while selectively choosing which content can wait.</p>



<h2 class="wp-block-heading" id="next-seo-combining-ssg-ssr">Combining SSG and SSR&nbsp;</h2>



<p class="wp-block-paragraph">SSG and SSR both have their strengths and weaknesses, so why can&#8217;t we have a website that utilizes both? NextJs has made this a reality, allowing devs to specify whether a page is SSG or SSR with only a few lines of code.</p>



<p class="wp-block-paragraph">Using NextJs, each page is represented by a page component, and within this component is where the React and Next code goes. Deciding whether a particular component is SSG or SSR is a simple matter of including a NextJs lifecycle method at the end of the component.</p>



<p class="wp-block-paragraph">To create a static page, we include the <strong>getStaticProps() </strong>method.</p>



<p class="wp-block-paragraph">To create a server rendered page, we include the <strong>getServerSideProps() </strong>method.</p>



<p class="wp-block-paragraph">Simple right? Well, obviously things can get complex when implementing any data-driven architecture. However, it&#8217;s always great when an underlying principle can be explained in such simple terms.</p>



<h2 class="wp-block-heading">Combining SSR and SSG with Deferred Loading</h2>



<p class="wp-block-paragraph">We mentioned earlier that NextJs allows developers to prioritize content, specifying which content can wait until other more important content is finished loading. This is an important feature for SEO, because it can often be secondary content such as modal boxes and images at the bottom of a page that slow things down and result in poor search engine optimization.</p>



<p class="wp-block-paragraph">When dynamic imports are combined with SSG and SSR, we can then yield React in all its magnificent glory. This is what NextJs accomplishes seamlessly, offering developers the best of React and decent search engine optimization without worrying about many of the complex details of implementation.</p>



<h2 class="wp-block-heading">Code Splitting and Bundling with NextJs</h2>



<p class="wp-block-paragraph">Deferred loading is accomplished by splitting up React bundles into smaller chunks of code that can be served on demand.</p>



<p class="wp-block-paragraph">At a high level view, the steps could be described as follows:</p>



<ol class="wp-block-list">
<li>A developer runs a build prior to placing the app in production.</li>



<li>The build tool and transpiler, usually WebPack and Babel, bundles all the React/Next code into a vanilla Javascript file.</li>



<li>The bundle is then broken down, or split, into smaller chunks of code to be served as needed.</li>
</ol>



<p class="wp-block-paragraph">React templates usually come equipped to handle steps one and two out of the box. However, things become a little more complicated when configuring step 3, which is why NextJs comes with the next/dynamic library to streamline the process.</p>



<h2 class="wp-block-heading" id="next-seo-image-optimization">NextJs Image Optimization</h2>



<p class="wp-block-paragraph">No conversation about SEO is complete without the mention of <a href="https://www.ohmycrawl.com/nextjs/image-optimization/">Next Js image optimization</a>. You&#8217;d be hard pressed to find a site that doesn&#8217;t use images in some fashion, and Google is pretty picky about how these images are served.</p>



<p class="wp-block-paragraph">According to the Google developer docs, in terms of search engine optimization, Google considers everything from image file size and placement to proper context and URL naming convention. The NextJs Image component can&#8217;t help with everything, but it certainly helps with proper image formatting.</p>



<p class="wp-block-paragraph">When an image is imported via the NextJs Image component, it is automatically compressed to the highly efficient webp formatting.</p>



<p class="wp-block-paragraph">The image is made available in multiple sizes to be served depending on screen resolution in order to achieve optimal page load speed.</p>



<p class="wp-block-paragraph">This is awesome for search engine optimization! NextJs scores yet another point for enhancing SEO metrics.</p>



<h2 class="wp-block-heading" id="next-seo-handling-metadata">Handling metadata with NextJs</h2>



<p class="wp-block-paragraph">For any site built with the goal of organic discoverability, it’s important to consider how your team plans on handling metadata maintenance. NextJs helps facilitate this by offering components for maintaining the <a href="https://www.ohmycrawl.com/nextjs/seo/">head tag</a>, as well as <a href="https://www.ohmycrawl.com/nextjs/sitemap/">sitemap</a> and <a href="https://www.ohmycrawl.com/nextjs/robots-txt-2/">robots</a> files.</p>



<p class="wp-block-paragraph">We won’t go over these SEO related topics in detail here. If you’d like to learn more, head over to our comprehensive write-ups in the links above.</p>



<h2 class="wp-block-heading">NextJs is an Abstraction of React&nbsp;</h2>



<p class="wp-block-paragraph">When dealing with frameworks on top of frameworks, it&#8217;s important not to lose sight of all the abstraction going on. React is a framework that abstracts a ton of web development features, and NextJs is a framework that abstracts much of React.</p>



<p class="wp-block-paragraph">React is capable of doing everything NextJs does, if you’re willing to put in the work. The name for SSR and SSG in the React world is isomorphic React, which is a fancy way to say that React can be coded in much the same way regardless of the environment (browser, server, etc.).</p>



<p class="wp-block-paragraph">Many developers opted to stay away from isomorphic React because of its complexity, which in many ways led to the ubiquity of client-side SPAs and the subsequent SEO problems.</p>



<p class="wp-block-paragraph">NextJs simplifies the implementation of isomorphic React, offering developers an easier way to code SSR and SSG React apps and less search engine optimization related problems.</p>



<h2 class="wp-block-heading" id="next-seo-overview-conclusion">NextJs SEO | Overview and Concluding Thoughts</h2>



<p class="wp-block-paragraph">Using NextJs to build websites allows developers to leverage React and all of its great features in a way that doesn’t compromise SEO performance. By implementing isomorphic React and streamlining the process of creating an SSG and/or SSR solution, developers and clients get the best of both worlds.</p>



<p class="wp-block-paragraph">NextJs is more than just a tool for improving SEO metrics and Google rank. However, when thought of in the context of search engine optimization, it becomes apparent that Next is a great tool for building websites spanning across multiple industries.</p>



<h2 class="wp-block-heading">Where to go from here?</h2>



<p class="wp-block-paragraph">NextJs can pretty much handle whatever we throw at it. In the ever evolving world of SEO, it&#8217;s comforting to build with a framework that keeps up with the pace of these shifts and curves.When a framework is built that can efficiently handle such a broad spectrum of projects, it&#8217;s worth taking note. We recommend reading about React and NextJs on <a href="https://www.ohmycrawl.com/blog/">our blog</a>, and diving into the NextJs world with confidence!</p>
<p>The post <a href="https://www.ohmycrawl.com/nextjs/seo/">Next JS SEO</a> appeared first on <a href="https://www.ohmycrawl.com">OhMyCrawl</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.ohmycrawl.com/nextjs/seo/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Next.js Image Optimization</title>
		<link>https://www.ohmycrawl.com/nextjs/image-optimization/</link>
					<comments>https://www.ohmycrawl.com/nextjs/image-optimization/#respond</comments>
		
		<dc:creator><![CDATA[EditorOhMyCrawl]]></dc:creator>
		<pubDate>Sat, 10 Jun 2023 13:17:45 +0000</pubDate>
				<category><![CDATA[Next.js]]></category>
		<guid isPermaLink="false">https://www.ohmycrawl.com/?p=21112</guid>

					<description><![CDATA[<p>Building modern web apps with any framework almost always involves the need for image optimization, and the NextJs image optimization is no exception. Image optimization is important for several reasons, which we&#8217;ll go over, along with how these concepts apply to Next.js specifically. TL;DR: NextJs Image Optimization &#38; Quick Links If your website images are ... <a title="Next.js Image Optimization" class="read-more" href="https://www.ohmycrawl.com/nextjs/image-optimization/" aria-label="More on Next.js Image Optimization">Read more</a></p>
<p>The post <a href="https://www.ohmycrawl.com/nextjs/image-optimization/">Next.js Image Optimization</a> appeared first on <a href="https://www.ohmycrawl.com">OhMyCrawl</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Building modern web apps with any framework almost always involves the need for image optimization, and the NextJs image optimization is no exception. <a href="https://en.wikipedia.org/wiki/Image">Image</a> optimization is important for several reasons, which we&#8217;ll go over, along with how these concepts apply to <a href="https://www.ohmycrawl.com/nextjs/">Next.js</a> specifically.</p>



<div class="wp-block-columns has-background is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex" style="background-color:#fff4cf">
<div class="wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:33.33%"><div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><img loading="lazy" decoding="async" width="313" height="280" src="https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs.jpg" alt="" class="wp-image-21460" style="aspect-ratio:1.1168831168831168;width:284px;height:auto" srcset="https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs.jpg 313w, https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs-300x268.jpg 300w" sizes="auto, (max-width: 313px) 100vw, 313px" /><figcaption class="wp-element-caption"><em>SEO Consultant </em></figcaption></figure>
</div></div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:66.66%">
<p class="has-text-align-center has-large-font-size wp-block-paragraph">Free Weekly SEO Newsletter</p>



<p class="wp-block-paragraph">Hey! I&#8217;m Scott, I&#8217;ve been an SEO consultant for nearly 10 years. Get on my weekly newsletter to get..</p>



<ul class="wp-block-list">
<li>Weekly SEO updates, keep up with the latest and greatest.</li>



<li>How we grow websites from zero to millions of visitors</li>



<li>A bunch of SEO tips and Tricks you won&#8217;t find anywhere else test</li>
</ul>


<div class="gb-button-wrapper gb-button-wrapper-88826626">

<a class="gb-button gb-button-d3a6a344 gb-button-text" href="#cb717b282f"><strong>Get On The Newsletter</strong></a>

</div></div>
</div>



<h3 class="wp-block-heading">TL;DR: NextJs Image Optimization &amp; Quick Links</h3>



<p class="wp-block-paragraph">If your website images are huge, they will have a negative effect on search engine rankings. If you compress them, you’ll likely see a meaningful increase in organic traffic.</p>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<ul class="wp-block-list">
<li><a href="#next-image-opt-basics">Basic Image Optimization</a></li>



<li><a href="#next-image-opt-concepts">Image Optimization Concepts</a></li>



<li><a href="#next-image-opt-component">NextJs Image Component</a></li>
</ul>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<ul class="wp-block-list">
<li><a href="#next-image-opt-testing">Optimization by the Image Component</a></li>



<li><a href="#next-image-opt-comp">NextJs Image Component vs HTML Image Tag</a></li>



<li><a href="#next-image-opt-overview">Overview and Conclusion</a></li>
</ul>
</div>
</div>



<h2 class="wp-block-heading">Why is image optimization and compression important for SEO?</h2>



<p class="wp-block-paragraph">Fast page speed and excellent user experience translates to great SEO metrics. It’s important to know and apply best practices to ensure your project can rank in a modern and competitive online marketplace.</p>



<p class="wp-block-paragraph">Facilitating image optimization is a focal point for many frameworks. NextJs has a unique approach to this problem, offering an Image component that’s extremely convenient, effective, and easy to use.</p>



<h2 class="wp-block-heading" id="next-image-opt-basics">How to Optimize Images With NextJs | The Basics</h2>



<p class="wp-block-paragraph">The NextJs framework comes equipped with an image component that has many great features, such as automatic image compression and responsive image loaders. The Image component converts images to the .webp file format, which we’ll talk more about later.</p>



<p class="wp-block-paragraph">The Image component accepts an image file as a parameter (remote image), or an imported image object (local image). Remote images within your project must be located in the<strong> /public</strong> directory of your project.</p>



<p class="wp-block-paragraph">At build time, the image will be converted and compressed accordingly, and plugged-in to a standard HTML tag for the client to consume.</p>



<p class="wp-block-paragraph">Basic usage is simple, here’s an example:</p>



<pre class="wp-block-code"><code>import Image from 'next/image';
 
export default function ImgComponent() {
  return (
    &lt;&gt;
         &lt;Image src="/example.png" height={150} width={150} alt="Sample" /&gt;
    &lt;/&gt;</code></pre>



<p class="wp-block-paragraph">Notice that we had to set the width and height manually. That’s because this example utilizes a remote image rather than a local image (more on that later).</p>



<p class="wp-block-paragraph">This simple JSX markup does a lot of work under the hood, converting and compressing your image to the .webp format while preserving image quality.</p>



<p class="wp-block-paragraph">We&#8217;re going to get a little more in-depth with the Image component in a bit. However, let’s do a quick review on SEO optimization concepts as pertains to images on the web.</p>



<h2 class="wp-block-heading" id="next-image-opt-concepts">SEO | Image Optimization Concepts</h2>



<p class="wp-block-paragraph">Many concepts are universal regarding image optimization on the web, and we should go over some of the more important aspects before diving into the NextJs Image component and seeing what it can do.</p>



<h3 class="wp-block-heading"><strong>Decrease the file size for faster page load speed.</strong></h3>



<p class="wp-block-paragraph">Usually, the overall goal is to serve the smallest possible file size while preserving the image quality. There are multiple ways to accomplish this, from compression to responsive image loaders. Or both.</p>



<h3 class="wp-block-heading"><strong>Name image files appropriately.</strong></h3>



<p class="wp-block-paragraph">When creating images for your site, it’s important to give the image file a relevant name for what the image is depicting. This also goes for the image alt tag and caption; it’s important to show Google that your media is relevant to the actual content you’re offering the user.</p>



<h3 class="wp-block-heading"><strong>Utilizing content delivery networks.</strong></h3>



<p class="wp-block-paragraph">Content delivery networks (CDNs) are services that will cache your site&#8217;s content on servers all over the country. When someone requests your site, the nearest CDN server will respond with an up to date cache of whichever media the client requested, significantly increasing page speed. This tech doesn&#8217;t only apply to images, but it&#8217;s relevant for our purposes.</p>



<h3 class="wp-block-heading"><strong>Choosing the right file format.</strong></h3>



<p class="wp-block-paragraph">There are 5 main image file formats to consider when it comes to web design. Let&#8217;s take a quick look at what each brings to the table:</p>



<ul class="wp-block-list">
<li>JPEG &#8211; Best for larger photos. Lossy and raster based, which means it will lose quality during compression.</li>



<li>PNG &#8211; Preserves transparent backgrounds, which comes in handy. Lossless, which means even after compression the file size will only shrink so much.</li>



<li>WebP &#8211; Optimal compression over jpeg or png by about 25%, and preserves transparency. This format is used by NextJs Image because it offers a good middle ground between quality and optimization.</li>



<li>AVIF &#8211; Same as webp but with 20% more compression. Takes 20% longer to compress on the fly, which is why NextJs opts for WebP.</li>



<li>SVG &#8211; Best for line drawings that can scale while remaining small in size, such as logos.</li>
</ul>



<p class="wp-block-paragraph">Although NextJs does a good job producing quality compressed images on the fly with the webp format, it&#8217;s important to be familiar with these options.&nbsp;</p>



<p class="wp-block-paragraph">When it comes to images, unique cases tend to present themselves when least expected, and this knowledge will help you identify when the Image component may need to be tweaked, or abandoned altogether.</p>



<h2 class="wp-block-heading" id="next-image-opt-component">NextJs Image Component | An Optimization Tool</h2>



<p class="wp-block-paragraph">It&#8217;s important to remember that the Image component is simply an extension of the HTML img tag. There&#8217;s no unfamiliar magic going on here, it&#8217;s just another optional optimization tool offered by the NextJs framework.</p>



<p class="wp-block-paragraph">Let&#8217;s take a glance at what the Image component has to offer:</p>



<ul class="wp-block-list">
<li><strong>Image loader &#8211; </strong>Image loaders are functions that generate the URL endpoints for your images. NextJs defaults to its own loader, but allows you to use third-party loaders, or set up a custom loader. The default image loader will generate multiple images to be served at specific breakpoints depending on the device’s screen size, using the srcset property.</li>



<li><strong>No cumulative layout shift (CLS) –</strong> Using techniques to ensure a height and width value is always set on your images, CLS is avoided. CLS is when a page layout shifts as images are loaded into the page, creating an annoying effect that’s bad for UX. This is a subtle but important SEO metric that is used by Google to rank web pages.</li>



<li><strong>Automatic image conversion and compression – </strong>NextJs defaults to using <strong>squoosh, </strong>a tool built by the guys at GoogleChromeLabs,<strong> </strong>to convert images to the webp format. This process is completely automated and doesn’t require any extra work.</li>



<li><strong>Lazy loading &#8211; </strong>A technique for increasing page speed by only loading an image once it&#8217;s in the viewport, i.e visible on the screen. The Image component defaults to using lazy loading.</li>



<li><strong>Image placeholder &#8211; </strong>A feature that allows the developer to specify a placeholder image or blur that is displayed until the actual image has completed loading. Serving some content instead of nothing is preferable, even if for only a brief moment.</li>
</ul>



<p class="wp-block-paragraph">Now that we have a good idea of what the Image component brings to the table, let’s take a closer look at the two ways we can load image files into the component.</p>



<h2 class="wp-block-heading">The src Property | Local vs Remote Images</h2>



<p class="wp-block-paragraph">As we saw in the first example, the src property is where we set the location of the image. In the example, we used a relative URL, which tells NextJs that our image is remote. This may seem strange because in this case, the image is actually located in our local projects /public folder. However, this definition makes perfect sense. NextJs can only have access to the file at build time if it’s imported into the component. Therefore, if the image isn’t imported, you must specify the width and height of the remote image because the Image component has no way to obtain this information without direct access.</p>



<h3 class="wp-block-heading"><strong>The image exists locally, but it’s <em>remote </em>relative to the component.</strong></h3>



<p class="wp-block-paragraph">Although using remote images is fairly common, it can be a pain configuring a viable solution that keeps the image aspect ratio without any clipping. This is why it’s usually recommended to use local images and the default NextJs image loader, which works really well for most cases anyways.</p>



<p class="wp-block-paragraph">That being said, let’s take a look at what kind of results we can achieve by importing an image locally into our component.</p>



<h2 class="wp-block-heading" id="next-image-opt-testing">Testing the NextJs Image Component Optimization</h2>



<p class="wp-block-paragraph">We’ll start with a test image, test.png, that has a transparent background and is 206kb in size. Not huge, but we can do better. So, let’s import this image into our component and check out the output:</p>



<pre class="wp-block-code"><code>import Image from 'next/image';
import testImg from ‘../public/test.png’;
 
export default function ImgComponent() {
  return (
    &lt;&gt;
         &lt;Image src={testImg} alt="Sample" /&gt;
    &lt;/&gt;</code></pre>



<p class="wp-block-paragraph"><em><strong>Note: </strong>We didn’t need to explicitly declare the width and height, because we used a local image.</em></p>



<p class="wp-block-paragraph">After saving this component and refreshing our browser, we can download the image and view its properties.</p>



<p class="wp-block-paragraph">As expected, our .png image is now in the .webp format. But the impressive metric here is the file size, coming in at a tiny 46.5kb! That’s a 72% decrease in size from our original 206kb, while maintaining the original image resolution; not bad at all.</p>



<p class="wp-block-paragraph">We can achieve even more impressive results in some cases, and less in others. The resulting file size is largely dependent on a number of factors, such as color type and image detail. Behind the scenes, the Squoosh compression engine is doing great things.</p>



<h3 class="wp-block-heading">How to disable image optimization for NextJs?</h3>



<p class="wp-block-paragraph">Disabling image optimization in your NextJs app is as simple as using a standard HTML &lt;img /&gt; tag. Let’s take a look at how this works, and when you may opt for this method rather than utilizing the Image component.</p>



<h2 class="wp-block-heading" id="next-image-opt-comp">NextJs Image vs HTML img Tag | Which is better?</h2>



<p class="wp-block-paragraph">In most cases, the Image component will usually be the optimal solution over a standard HTML img tag. However, there are a few edge cases where utilizing a standard HTML could be beneficial.</p>



<h3 class="wp-block-heading"><strong>Some Reasons for using HTML img Tag Over Next Image</strong></h3>



<ul class="wp-block-list">
<li>For cases where the dimensions of remote images may be unknown. This is because (for remote images) the NextJs Image component requires a height and width property, or a layout property. So, if you’re unsure of the dimensions or aspect ratio, the standard img tag offers a little more flexibility with CSS styling.</li>



<li>When you’d like to use advanced effects libraries like framer-motion, you’ll need to use the standard img tag.</li>
</ul>



<p class="wp-block-paragraph">Using a standard HTML img tag is simple. Just plug in the `&lt;img /&gt;` tag in place of where you would use your Next Image component. All the standard features of React JSX transpiling with Babel still apply when using Next.</p>



<p class="wp-block-paragraph">Despite the above cases, using the Image component is usually preferred. It can drastically speed up development while benefiting from the inherent optimization features that can really speed up development without compromising <a href="https://www.ohmycrawl.com/nextjs/seo/">SEO best practices</a>.</p>



<h2 class="wp-block-heading" id="next-image-opt-overview">NextJs Image Optimization | Overview and Conclusion</h2>



<p class="wp-block-paragraph">As we’ve seen, the NextJs Image component is a powerful tool for quickly achieving optimal <a href="https://www.ohmycrawl.com/nextjs/seo/">Nextjs SEO</a> performance. It can be quickly set up to drastically compress images on the fly, while preserving image properties such as background transparency, dimensions, and overall quality.</p>



<p class="wp-block-paragraph">NextJs is a flexible framework, and gives developers the freedom to discard the Image component completely. If you’re comfortable with your current method of image optimization, you can simply opt for using the traditional HTML img tag, and apply styles or other optimizations as you see fit.</p>



<p class="wp-block-paragraph">In our opinion, it’s worth setting aside some time to fully understand the ins and outs of this component’s features. We went over most of the basic usage in this article, but it’s always a good idea to head over to the<a href="https://nextjs.org/docs/api-reference/next/image"> NextJs docs</a> and familiarize yourself with all the little details.&nbsp;</p>
<p>The post <a href="https://www.ohmycrawl.com/nextjs/image-optimization/">Next.js Image Optimization</a> appeared first on <a href="https://www.ohmycrawl.com">OhMyCrawl</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.ohmycrawl.com/nextjs/image-optimization/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Best CMS for Next.js</title>
		<link>https://www.ohmycrawl.com/nextjs/best-cms/</link>
					<comments>https://www.ohmycrawl.com/nextjs/best-cms/#respond</comments>
		
		<dc:creator><![CDATA[ScottySEO]]></dc:creator>
		<pubDate>Fri, 16 Dec 2022 22:11:10 +0000</pubDate>
				<category><![CDATA[Next.js]]></category>
		<guid isPermaLink="false">https://www.ohmycrawl.com/?p=21588</guid>

					<description><![CDATA[<p>Next.js is a popular JavaScript framework that is used to build web applications and websites. It offers a range of features and tools that make it easy for developers to create fast, modern, and scalable applications. When it comes to managing and organizing content for a Next.js application, choosing the right Content management system (CMS) ... <a title="Best CMS for Next.js" class="read-more" href="https://www.ohmycrawl.com/nextjs/best-cms/" aria-label="More on Best CMS for Next.js">Read more</a></p>
<p>The post <a href="https://www.ohmycrawl.com/nextjs/best-cms/">Best CMS for Next.js</a> appeared first on <a href="https://www.ohmycrawl.com">OhMyCrawl</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph"><a href="https://www.ohmycrawl.com/nextjs/">Next.js</a> is a popular JavaScript framework that is used to build web applications and websites. It offers a range of features and tools that make it easy for developers to create fast, modern, and scalable applications. </p>



<p class="wp-block-paragraph">When it comes to managing and organizing content for a Next.js application, choosing the right Content management system (CMS) is crucial. In this article, we&#8217;ll explore some of the best CMS options for Next.js and how they can help you build and maintain a successful web project. From headless CMS platforms to open-source solutions, there are a variety of options available to suit different needs and budgets. We&#8217;ll take a look at the features, benefits, and drawbacks of each CMS to help you make an informed decision.</p>



<p class="wp-block-paragraph">Here are the most popular choices:</p>



<ol class="wp-block-list">
<li>Suncel &#8211; Our top pick, amazing CMS for any Next.js project.</li>



<li>Contentful: A cloud-based headless CMS that allows developers to build custom applications using its API.</li>



<li>Strapi: An open-source headless CMS that can be easily integrated with Next.js.</li>



<li>Ghost: A simple, open-source blogging platform that can be used as a headless CMS.</li>



<li>Netlify CMS: An open-source CMS that is designed to work with static site generators like Next.js.</li>



<li>KeystoneJS: A powerful, open-source CMS that is built on top of the Express.js framework and can be easily integrated with Next.js.</li>
</ol>



<h2 class="wp-block-heading">Suncel</h2>



<p class="wp-block-paragraph"><a href="http://suncel.io">Suncel</a> is a CMS that is on the rise. It is only dedicated to Next.js applications but can be easily plugged into an existing Next.js application.<br><br>This CMS requires a dev during the setup, but it is then usable by a content editor without any technical complexity.<br><br>Suncel is particularly adapted for websites that want to produce a lot of content, quickly with excellent indexation and a very good score for their core web vitals.<br><br>The CMS also has an SEO module that allows you to quickly edit your META, META OG, and structured data for SEO.To produce content, the CMS is also equipped with block templates with pre-filled content.<br><br>From the developers&#8217; point of view, there are also many advantages:<br>&#8211; simple integration on a Next.js app<br>&#8211; construction of Blocks which are then infinitely reusable by content editors<br>&#8211; possibility to create page templates (predefined suite of Blocks)<br>&#8211; automatic sitemap management<br>&#8211; customizable settings for each Block<br>&#8211; Admin customizable in React<br>&#8211; No routing system is needed to fit the CMS</p>



<h2 class="gb-headline gb-headline-6a408291 gb-headline-text">Contentful</h2>



<p class="wp-block-paragraph">Contentful is a cloud-based headless CMS that is often considered one of the best options for Next.js projects. There are several reasons why Contentful is highly regarded in the development community:</p>



<ol class="wp-block-list">
<li>Flexibility: Contentful allows developers to create custom content models, so they can structure their data in a way that makes sense for their application. This makes it easy to create and manage complex content structures.</li>



<li>Scalability: Contentful is built to scale with your project, so you don&#8217;t have to worry about performance issues as your application grows.</li>



<li>Integration: Contentful has a robust API and wide range of integrations, making it easy to connect to other tools and services.</li>



<li>User experience: Contentful has a user-friendly interface that makes it easy for content creators to manage and publish content.</li>



<li>Strong community: Contentful has a large and active community of developers, which means there are plenty of resources and support available for users.</li>
</ol>



<p class="wp-block-paragraph">Overall, Contentful is a powerful and flexible CMS that is well-suited for Next.js projects of all sizes.</p>



<h2 class="gb-headline gb-headline-0be852e6 gb-headline-text">Strapi</h2>



<p class="wp-block-paragraph">Strapi is an open-source headless CMS that is often used with Next.js projects. Some of the key features and benefits of Strapi include:</p>



<ol class="wp-block-list">
<li>Ease of use: Strapi has a user-friendly interface that makes it easy for developers to create and manage their content.</li>



<li>Customization: Strapi allows developers to create custom content types and fields, which gives them more control over their data and how it is structured.</li>



<li>Performance: Strapi is built to be fast and efficient, so it can handle large amounts of content without slowing down.</li>



<li>Integration: Strapi has a powerful API and supports a range of integrations, making it easy to connect to other tools and services.</li>



<li>Scalability: Strapi can handle large amounts of traffic and is designed to scale with your project as it grows.</li>
</ol>



<p class="wp-block-paragraph">Overall, Strapi is a popular choice for developers looking for an open-source CMS that is easy to use and customize, and that can handle the demands of a growing project.</p>



<h2 class="wp-block-heading">Ghost</h2>



<p class="wp-block-paragraph">Ghost is an open-source blogging platform that is often used as a headless CMS for Next.js projects. Some of the key features and benefits of Ghost include:</p>



<ol class="wp-block-list">
<li>Simplicity: Ghost is designed to be a simple and lightweight platform that is easy to use and maintain.</li>



<li>Customization: Ghost allows developers to customize the look and feel of their site through themes and templates, and it also supports custom integrations and functionality through its API.</li>



<li>Performance: Ghost is built to be fast and efficient, so it can handle large amounts of content and traffic without slowing down.</li>



<li>User experience: Ghost has a clean and intuitive interface that makes it easy for content creators to manage and publish content.</li>



<li>Security: Ghost is focused on security and privacy, and it is regularly updated with the latest security patches and features.</li>
</ol>



<p class="wp-block-paragraph">Overall, Ghost is a good choice for developers looking for a simple, lightweight CMS that is easy to use and customize, and that is built with performance and security in mind.</p>



<h2 class="gb-headline gb-headline-a8b9e653 gb-headline-text">Netlify CMS</h2>



<p class="wp-block-paragraph">Netlify CMS is an open-source content management system that is designed to work with static site generators like Next.js. Some of the key features and benefits of Netlify CMS include:</p>



<ol class="wp-block-list">
<li>Ease of use: Netlify CMS has a simple and intuitive interface that makes it easy for content creators to manage and publish content.</li>



<li>Integration: Netlify CMS is designed to work seamlessly with static site generators like Next.js, and it can be easily integrated into an existing Next.js project.</li>



<li>Customization: Netlify CMS allows developers to create custom content types and fields, giving them more control over their data and how it is structured.</li>



<li>Performance: Netlify CMS is built to be fast and efficient, so it can handle large amounts of content without slowing down.</li>



<li>Security: Netlify CMS is regularly updated with the latest security patches and features, making it a secure choice for managing content.</li>
</ol>



<p class="wp-block-paragraph">Overall, Netlify CMS is a good choice for developers looking for an easy-to-use, open-source CMS that is designed to work with static site generators like Next.js.</p>



<h2 class="wp-block-heading">KeystoneJS</h2>



<p class="wp-block-paragraph">KeystoneJS is an open-source content management system that is built on top of the Express.js framework and can be easily integrated with Next.js. Some of the key features and benefits of KeystoneJS include:</p>



<ol class="wp-block-list">
<li>Scalability: KeystoneJS is built to handle large amounts of content and traffic, and it is designed to scale with your project as it grows.</li>



<li>Customization: KeystoneJS allows developers to create custom content types and fields, giving them more control over their data and how it is structured.</li>



<li>Integration: KeystoneJS has a powerful API and supports a range of integrations, making it easy to connect to other tools and services.</li>



<li>User experience: KeystoneJS has a user-friendly interface that makes it easy for content creators to manage and publish content.</li>



<li>Security: KeystoneJS is regularly updated with the latest security patches and features, making it a secure choice for managing content.</li>
</ol>



<p class="wp-block-paragraph">Overall, KeystoneJS is a powerful and flexible CMS that is well-suited for Next.js projects of all sizes. It offers a range of features and tools that make it easy for developers to create and manage complex content structures, and it is built to handle the demands of a growing project.</p>



<h2 class="wp-block-heading">Is WordPress a good cms for next js?</h2>



<p class="wp-block-paragraph">WordPress is a popular content management system that is used by millions of websites around the world. It is generally not considered to be the best choice for use with Next.js, however, as it is not optimized for building modern web applications and does not natively support server-side rendering.</p>



<p class="wp-block-paragraph">Next.js is a JavaScript framework that is designed for building fast, scalable, and modern web applications, and it is optimized for server-side rendering and performance. As such, it is generally better suited to work with headless CMS platforms like Contentful, Strapi, Ghost, Netlify CMS, or KeystoneJS, which are designed to provide content and data to be consumed by other applications.</p>



<p class="wp-block-paragraph">That being said, it is possible to use WordPress as a headless CMS with Next.js by using the WordPress REST API to retrieve data and content from a WordPress site. However, this approach may require more development effort and may not offer the same level of performance and scalability as using a native headless CMS.</p>
<p>The post <a href="https://www.ohmycrawl.com/nextjs/best-cms/">Best CMS for Next.js</a> appeared first on <a href="https://www.ohmycrawl.com">OhMyCrawl</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.ohmycrawl.com/nextjs/best-cms/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Next JS Server Side Rendering (SSR)</title>
		<link>https://www.ohmycrawl.com/nextjs/server-side-rendering-2/</link>
					<comments>https://www.ohmycrawl.com/nextjs/server-side-rendering-2/#respond</comments>
		
		<dc:creator><![CDATA[EditorOhMyCrawl]]></dc:creator>
		<pubDate>Sun, 10 Jul 2022 20:35:56 +0000</pubDate>
				<category><![CDATA[Next.js]]></category>
		<guid isPermaLink="false">https://www.ohmycrawl.com/?p=21127</guid>

					<description><![CDATA[<p>Next.js is a great framework that offers many features for enhancing NextJS SEO optimization and user-experience. One staple feature is server side rendering (SSR), which is essentially what the name implies. Much of the work needed to render your web page into HTML is handled on the server rather than the client.            Why is this ... <a title="Next JS Server Side Rendering (SSR)" class="read-more" href="https://www.ohmycrawl.com/nextjs/server-side-rendering-2/" aria-label="More on Next JS Server Side Rendering (SSR)">Read more</a></p>
<p>The post <a href="https://www.ohmycrawl.com/nextjs/server-side-rendering-2/">Next JS Server Side Rendering (SSR)</a> appeared first on <a href="https://www.ohmycrawl.com">OhMyCrawl</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph"><a href="https://www.ohmycrawl.com/nextjs/">Next.js</a> is a great framework that offers many features for enhancing <a href="https://www.ohmycrawl.com/nextjs/seo/">NextJS SEO</a> optimization and user-experience. One staple feature is server side rendering (SSR), which is essentially what the name implies. Much of the work needed to render your web page into HTML is handled on the server rather than the client.           </p>



<p class="wp-block-paragraph">Why is this significant? Well, NextJs is built on top of the React framework, and the React framework is typically used to build single page applications (SPAs). The default configuration for React SPAs is to only serve a barebones HTML shell to the client at first render, and subsequently send a bunch of Javascript files that finishes populating the HTML page with the actual content.</p>



<div class="wp-block-columns has-background is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex" style="background-color:#fff4cf">
<div class="wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:33.33%"><div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><img loading="lazy" decoding="async" width="313" height="280" src="https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs.jpg" alt="" class="wp-image-21460" style="aspect-ratio:1.1168831168831168;width:284px;height:auto" srcset="https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs.jpg 313w, https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs-300x268.jpg 300w" sizes="auto, (max-width: 313px) 100vw, 313px" /><figcaption class="wp-element-caption"><em>SEO Consultant </em></figcaption></figure>
</div></div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:66.66%">
<p class="has-text-align-center has-large-font-size wp-block-paragraph">Free Weekly SEO Newsletter</p>



<p class="wp-block-paragraph">Hey! I&#8217;m Scott, I&#8217;ve been an SEO consultant for nearly 10 years. Get on my weekly newsletter to get..</p>



<ul class="wp-block-list">
<li>Weekly SEO updates, keep up with the latest and greatest.</li>



<li>How we grow websites from zero to millions of visitors</li>



<li>A bunch of SEO tips and Tricks you won&#8217;t find anywhere else test</li>
</ul>


<div class="gb-button-wrapper gb-button-wrapper-88826626">

<a class="gb-button gb-button-d3a6a344 gb-button-text" href="#cb717b282f"><strong>Get On The Newsletter</strong></a>

</div></div>
</div>



<h2 class="wp-block-heading">TL;DR: Next JS SSR &amp; Quick Links</h2>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<ul class="wp-block-list">
<li><a href="#next-ssr-handles">How NextJs Handles SSR</a></li>



<li><a href="#next-ssr-lazy-vs-eager">Lazy Loading vs Eager Loading &#8211; Example</a></li>



<li><a href="#next-ssr-code-bundling-dynamic-imports">Importance of Code Bundling and Dynamic Imports</a></li>



<li><a href="#next-ssr-slow-pages">Troubleshooting Slow SSR Pages</a></li>
</ul>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<ul class="wp-block-list">
<li><a href="#next-ssr-app-wont-ssr">NextJs App Won&#8217;t Server Side Render</a></li>



<li><a href="#next-ssr-what-is-ssg">What is Static Site Generation</a></li>



<li><a href="#next-ssr-overview-conclusion">Overview and Conclusion</a></li>
</ul>
</div>
</div>



<h2 class="wp-block-heading">React SPA | Good for UX &#8212; Bad for SEO</h2>



<p class="wp-block-paragraph">This design pattern is great for developers, and is pretty good for user-experience in most cases as well (unless you have a terribly slow internet connection). However, GoogleBot isn’t too crazy about it, because Google’s crawlers want content fast, and waiting on all that Javascript to load isn’t conducive to serving up content quickly.</p>



<h2 class="wp-block-heading">What is SSR | A More In-Depth Discussion</h2>



<p class="wp-block-paragraph">SSR can differ greatly depending on the framework in question. In general, SSR is simply the rendering of HTML pages on the server. Using NextJs, that’s only part of the story.</p>



<h2 class="wp-block-heading" id="next-ssr-handles">How NextJs Handles SSR</h2>



<p class="wp-block-paragraph">NextJs has its own flavor of SSR that meshes well with the underlying React framework. First of all, when a page request is made to a NextJs app, one of two life cycle methods gets called. The method that tells Next to render the page on the server is called <strong>getServerSideProps.</strong></p>



<p class="wp-block-paragraph">This method allows the developer to do all kinds of cool stuff other than just telling Next to render on the server, such as injecting page related data on a per-request basis from an external API into the component props.</p>



<p class="wp-block-paragraph">However, the key feature that really sets NextJs apart from other non-React SSR technologies is its ability to ship code bundles with the generated HTML in a very efficient manner using next/dynamic imports with Suspense for lazy loading.</p>



<h2 class="wp-block-heading" id="next-ssr-lazy-vs-eager">Lazy Loading vs Eager Loading</h2>



<p class="wp-block-paragraph">When making explicit imports into your components, they are <em>eager </em>loaded. This means all resources are loaded as soon as the code is executed. This isn&#8217;t ideal for optimizing page load speed, because certain resource intensive components can often be loaded later on.</p>



<p class="wp-block-paragraph">Here&#8217;s a truncated example of explicit importing that results in eager loading:</p>



<pre class="wp-block-code"><code>import OneComponent from './OneComponent';
import TwoComponent from './TwoComponent';
 
export default function Home() {
  return (
    &lt;&gt;
        &lt;OneComponent /&gt;
        &lt;TwoComponent /&gt;
    &lt;/&gt;
)}</code></pre>



<p class="wp-block-paragraph">In contrast, <em>lazy</em> loading is a design pattern that allows certain pieces of code, React components in our case, to be prioritized and loaded only once other parts of the page have completed loading. NextJs offers the next/dynamic library and Suspense component to achieve lazy loading.</p>



<p class="wp-block-paragraph">Here&#8217;s a truncated example of lazy loading with next/dynamic and Suspense:</p>



<pre class="wp-block-code"><code>import dynamic from 'next/dynamic';
import { Suspense } from 'react';
import OneComponent from './OneComponent';
 
const TwoComponent = dynamic(() =&gt; import('./TwoComponent'), {
  suspense: true,
});
 
export default function Home() {
  return (
    &lt;&gt;
      &lt;OneComponent /&gt;
      &lt;Suspense fallback={`Loading...`}&gt;
         &lt;TwoComponent /&gt;
    &lt;/Suspense&gt;
    &lt;/&gt;
  )</code></pre>



<p class="wp-block-paragraph">In this example, TwoComponent is loaded only after OneComponent has finished loading. I.e It is loaded <em>lazily.</em></p>



<h2 class="wp-block-heading" id="next-ssr-code-bundling-dynamic-imports">Why is Code Bundling and Dynamic Imports so Important for SSR and SEO?</h2>



<p class="wp-block-paragraph">Imagine you&#8217;ve built a really cool super interactive app using NextJs, and your first client page request just came in. NextJs can then render the HTML, and include a few script tags pointing to all your fancy JavaScript that makes the page so interactive. Great! Well, not really. Your JavaScript files are probably going to be pretty bloated, and all that extra time waiting for the scripts to arrive is no good for SEO metrics.</p>



<p class="wp-block-paragraph">In comes dynamic imports and lazy loading. NextJs allows the developer to specify which script imports can wait, and which cannot, using the next/dynamic library.</p>



<p class="wp-block-paragraph">next/dynamic is an extension of React.lazy, and is therefore used with Suspense to achieve delayed hydration within your components.</p>



<h2 class="wp-block-heading">Real-World Example of Dynamic Imports Impacting SEO</h2>



<p class="wp-block-paragraph">Let&#8217;s say you have a complex modal box component with a 3d model inside that&#8217;s wired up to a button click at the bottom of a page. Logically, there&#8217;s no need to waste bandwidth packaging up this component and shipping it with your initial render. It will never be needed until well after your browser loads the initial content, and the user decides to scroll down and check stuff out.</p>



<p class="wp-block-paragraph">Using the next/dynamic library, we can tell NextJs to split the component code into a separate chunk, and lazy load it only after the important content has already finished loading. In other words, we can prioritize which scripts get loaded immediately, and which do not, in order to maximize page speed.</p>



<p class="wp-block-paragraph">This functionality has a tremendous impact in terms of SEO performance and scalability. It&#8217;s features such as this that make NextJs a solid frontrunner in the race of React based frameworks.</p>



<h2 class="wp-block-heading">Optimizing Images on the Fly With SSR and NextJs Image</h2>



<p class="wp-block-paragraph">The formula here is simple: Larger image files equals slower page speed and less SEO performance.</p>



<p class="wp-block-paragraph">Another great feature of SSR is the ability to do <a href="https://www.ohmycrawl.com/nextjs/image-optimization/">Next Js image optimization</a> on the fly. Not all frameworks include built-in functionality for handling this, whereas NextJs comes locked and loaded with the Image component.</p>



<p class="wp-block-paragraph">As a developer, it can be tedious receiving non-optimized images from a client to be placed on their site. The image must be processed through an image optimization engine such as squoosh, contributing to a less efficient development workflow.</p>



<p class="wp-block-paragraph">The NextJs Image component automates the process, taking your image during the SSR process and optimizing it prior to sending it to the client. It even streamlines the process of caching on content delivery networks, adding an extra SEO bonus.</p>



<h2 class="wp-block-heading" id="next-ssr-slow-pages">Troubleshooting Slow NextJs Pages That Use SSR</h2>



<p class="wp-block-paragraph">It&#8217;s not uncommon for developers new to NextJs to experience slower page speed than what they&#8217;ve come to expect in a React app. This isn&#8217;t because NextJs is inherently flawed, but rather because optimization techniques have probably been neglected.</p>



<p class="wp-block-paragraph">This isn&#8217;t just annoying for the end-user, it also sucks for SEO and is a problem that must be considered priority.</p>



<p class="wp-block-paragraph">Here&#8217;s some things to look for in your NextJs app if it just seems like things aren&#8217;t moving quick enough:</p>



<ol class="wp-block-list">
<li>Ensure any external API calls are handled in the most efficient manner possible. This lag is more noticeable on SSR apps in particular, because the API call must finish before the response is sent to the client. Of course, there&#8217;s ways to mitigate this lag if the API call cannot be optimized (Lazy/Suspense), but always look to optimize any external calls and return only the necessary data.</li>



<li>Starting with React 18 and onward, we can now utilize Lazy/Suspense on the server. This is a great feature that allows developers to specify components that should only load after all other non specified components are finished loading. This concept is similar to the dynamic imports we discussed earlier, but is actually more intuitive and easier to use.</li>



<li>Lack of image optimization is a common culprit when experiencing slow page speed. This is one of the easiest and most effective optimizations using NextJs. Check for any images over 100kb in size; chances are you can cut this in half (or more) using the NextJs Image component.</li>



<li>Cache frequently used content. This probably isn&#8217;t a cause of slow page speed with SSR, but using CDNs or preloaders can garner significant performance increases. After other internal optimizations, it&#8217;s a good idea to look into this feature to further increase the SEO and UX performance of your site.</li>
</ol>



<h2 class="wp-block-heading" id="next-ssr-app-wont-ssr">NextJs App Won&#8217;t Server Side Render</h2>



<p class="wp-block-paragraph">If you&#8217;re trying to achieve SSR with Next unsuccessfully, you&#8217;ve probably run into one of the following problems:</p>



<ol class="wp-block-list">
<li>Your app is being rendered as a client side SPA:<br>In this case, first ensure you&#8217;ve added the getServerSideProps lifecycle method to the page component in question. If that didn&#8217;t solve your problem, start by getting rid of each higher order component (HOC) one at a time, while checking if SSR kicks in after each removal. When it does, you&#8217;ve probably found an issue with a third party library, such as a redux provider, that&#8217;s causing a compatibility issue with NextJs SSR functionality. Check into the documentation, github issues, and check the versions. Usually such issues can be resolved with a little digging.</li>



<li>Your app is being statically generated:<br>Usually, this is simply a matter of ensuring you&#8217;re using <a href="https://www.ohmycrawl.com/nextjs/getstaticprops-vs-getserversideprops/">getServerSideProps instead of getStaticProps</a> within the page component in question.</li>
</ol>



<h2 class="wp-block-heading" id="next-ssr-what-is-ssg">What is Static Site Generation?</h2>



<p class="wp-block-paragraph">The fastest way for a server to serve a web page is if the page requested exists on the server as a static HTML file. No rendering or runtime magic; the HTML file is already there awaiting a request.</p>



<p class="wp-block-paragraph">That&#8217;s what static site generation (SSG) accomplishes. At build time, each page component is rendered into HTML, then an actual HTML file is &#8216;generated&#8217; and served from your hosting provider.</p>



<p class="wp-block-paragraph">SSG can outperform SSR in terms of overall SEO performance. However, SSG lacks flexible scalability because when changes are made, each HTML page must be regenerated and served out. This isn&#8217;t feasible for a highly dynamic site such as an action site or social media platform.</p>



<h2 class="wp-block-heading" id="next-ssr-overview-conclusion">NextJs SSR | Overview and Concluding Thoughts</h2>



<p class="wp-block-paragraph">As we&#8217;ve demonstrated, SSR is simply a design pattern that delegates much of the work to the server when building dynamic web apps. It&#8217;s a strong design pattern because, when done properly, you can achieve fast page speed and great UX without compromising important SEO metrics.</p>



<p class="wp-block-paragraph">NextJs accomplishes performant SSR by coming equipped with powerful optimization tools such as next/dynamic and the Next Image component. Many complex tasks such as code splitting and lazy loading are streamlined by Next, making it a great choice for teams looking to minimize overhead while not losing a ton of flexibility.</p>



<p class="wp-block-paragraph">Overall, NextJs and their unique flavor of SSR comes highly recommended. Give it a try using the concepts within this article; you won&#8217;t be disappointed.</p>
<p>The post <a href="https://www.ohmycrawl.com/nextjs/server-side-rendering-2/">Next JS Server Side Rendering (SSR)</a> appeared first on <a href="https://www.ohmycrawl.com">OhMyCrawl</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.ohmycrawl.com/nextjs/server-side-rendering-2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>getStaticProps vs getServerSideProps for Next JS</title>
		<link>https://www.ohmycrawl.com/nextjs/getstaticprops-vs-getserversideprops/</link>
					<comments>https://www.ohmycrawl.com/nextjs/getstaticprops-vs-getserversideprops/#respond</comments>
		
		<dc:creator><![CDATA[EditorOhMyCrawl]]></dc:creator>
		<pubDate>Wed, 01 Jun 2022 11:15:01 +0000</pubDate>
				<category><![CDATA[Next.js]]></category>
		<guid isPermaLink="false">https://www.ohmycrawl.com/?p=21034</guid>

					<description><![CDATA[<p>NextJs is a framework built on ReactJs, used for improving page performance and overall user experience. The problem NextJs solves is related to the nature of single page applications (SPAs), and how they render in the browser. SPAs built with ReactJs initially load an empty HTML shell in the browser, which is then populated with ... <a title="getStaticProps vs getServerSideProps for Next JS" class="read-more" href="https://www.ohmycrawl.com/nextjs/getstaticprops-vs-getserversideprops/" aria-label="More on getStaticProps vs getServerSideProps for Next JS">Read more</a></p>
<p>The post <a href="https://www.ohmycrawl.com/nextjs/getstaticprops-vs-getserversideprops/">getStaticProps vs getServerSideProps for Next JS</a> appeared first on <a href="https://www.ohmycrawl.com">OhMyCrawl</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">NextJs is a framework built on ReactJs, used for improving page performance and overall user experience. The problem NextJs solves is related to the nature of single page applications (SPAs), and how they render in the browser.</p>



<p class="wp-block-paragraph"><br>SPAs built with ReactJs initially load an empty HTML shell in the browser, which is then populated with the rest of the HTML content using Javascript. This technique is great for dynamic web apps that offer a rich user experience. However, because Googlebot crawlers want content fast, it’s not so great for <a href="https://www.ohmycrawl.com/nextjs/seo/">Next JS SEO</a>.</p>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading">TL;DR: getServer Vs getStatic Quick Links</h2>



<p class="wp-block-paragraph">For those of us who want answers quickly:</p>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<ul class="wp-block-list">
<li><a href="#gspvsgssp-overview">getStaticProps Vs getServerSideProps Quick Overview</a></li>



<li><a href="#gspvsgssp-gsp-example">Examples of getStaticProps</a></li>
</ul>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<ul class="wp-block-list">
<li><a href="#gspvsgssp-gssp-example">Examples of getServerSideProps</a></li>



<li><a href="#gspvsgssp-difference">What&#8217;s the Difference?</a></li>
</ul>
</div>
</div>



<div class="wp-block-columns has-background is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex" style="background-color:#fff4cf">
<div class="wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:33.33%"><div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><img loading="lazy" decoding="async" width="313" height="280" src="https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs.jpg" alt="" class="wp-image-21460" style="aspect-ratio:1.1168831168831168;width:284px;height:auto" srcset="https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs.jpg 313w, https://www.ohmycrawl.com/wp-content/uploads/2022/09/nextjs-300x268.jpg 300w" sizes="auto, (max-width: 313px) 100vw, 313px" /><figcaption class="wp-element-caption"><em>SEO Consultant </em></figcaption></figure>
</div></div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:66.66%">
<p class="has-text-align-center has-large-font-size wp-block-paragraph">Free Weekly SEO Newsletter</p>



<p class="wp-block-paragraph">Hey! I&#8217;m Scott, I&#8217;ve been an SEO consultant for nearly 10 years. Get on my weekly newsletter to get..</p>



<ul class="wp-block-list">
<li>Weekly SEO updates, keep up with the latest and greatest.</li>



<li>How we grow websites from zero to millions of visitors</li>



<li>A bunch of SEO tips and Tricks you won&#8217;t find anywhere else test</li>
</ul>


<div class="gb-button-wrapper gb-button-wrapper-88826626">

<a class="gb-button gb-button-d3a6a344 gb-button-text" href="#cb717b282f"><strong>Get On The Newsletter</strong></a>

</div></div>
</div>



<h2 class="wp-block-heading">How NextJs Helps Solve the SEO Problem With SPAs</h2>



<p class="wp-block-paragraph">NextJs helps solve this problem by utilizing ReactJs to render on the server side, either at build time or at run time. Rendering at build-time amounts to what is known as static site generation (SSG), while rendering at run time (per request) is known as <a href="https://www.ohmycrawl.com/nextjs/server-side-rendering-2/">server side rendering</a> (SSR).&nbsp;</p>



<p class="wp-block-paragraph">This technique is also known as isomorphic React, a fancy phrase that simply means React that runs on the server.&nbsp;</p>



<p class="wp-block-paragraph">Rendering React into HTML on the server offers the best of both worlds; great dev tooling and UX while still feeding content to Googlebot in a timely manner.</p>



<p class="wp-block-paragraph">NextJs ships with two methods for accomplishing this work on the server: <strong>getStaticProps() </strong>and<strong> getServerSideProps(). </strong>These methods can be included in any React component built using Next, which will feed the component with props data either at build time or at run time.&nbsp;</p>



<h2 class="wp-block-heading" id="gspvsgssp-difference">getStaticProps and getServerSideProps | What’s the Difference?</h2>



<p class="wp-block-paragraph">getStaticProps and getServerSideProps can be defined as follows:</p>



<ul class="wp-block-list">
<li><strong>getStaticProps():</strong> A method that tells the Next component to populate props and render into a static HTML page at <em>build</em> <em>time.</em>&nbsp;</li>



<li><strong>getServerSideProps():</strong> A method that tells the Next component to populate the props and render into a static HTML page at <em>run time.</em></li>
</ul>



<p class="wp-block-paragraph">Rendering at <em>build time</em> with <strong>getStaticProps()</strong> means that prior to hosting the page, the developer (or automation tool) converts the React into raw HTML pages, and only then are the pages hosted and served to clients. Raw HTML pages are optimal for SEO and fast page loading.</p>



<p class="wp-block-paragraph">Rendering at <em>run time </em>with <strong>getServerSideProps()</strong><em> </em>means that the site is live and hosted with React components sitting on the server awaiting a request. However, when a request is made, the server doesn’t send the Javascript React files to the client for rendering. Instead, NextJs tells React to go ahead and render these components into HTML <em>in real time, </em>then send the HTML to the client.</p>



<h2 class="wp-block-heading">When to use getStaticProps or getServerSideProps?</h2>



<p class="wp-block-paragraph">Determining which method to use depends largely on the nature of your page&#8217;s data requirements.&nbsp;</p>



<p class="wp-block-paragraph">If you need a lot of dynamic data on your page, it’s more scalable to render your page at run time (SSR), and therefore getServerSideProps would be the preferred method.&nbsp; Pages built using getServerSideProps for SSR won’t be as fast as SSG, however, it is optimal when compared to utilizing a standard SPA framework.</p>



<p class="wp-block-paragraph">If your page is more simple in nature, such as a blog post, you’ll get a performance boost rendering a static HTML page at build time (SSG), and therefore getStaticProps would be preferred. Pages built using getStaticProps for SSG will be very fast.</p>



<h2 class="wp-block-heading" id="gspvsgssp-gsp-example">Code Examples of getStaticProps</h2>



<p class="wp-block-paragraph">If you’re familiar with the React framework, implementing Next doesn’t have a huge learning curve. However, it takes a little getting used to. Remember, NextJs is built on React, so we’re still just coding React components under the hood.&nbsp;</p>



<p class="wp-block-paragraph">Let’s take a look at the raw getStaticProps method straight from the <a href="https://nextjs.org/docs/basic-features/data-fetching/get-static-props">NextJs docs</a> before viewing it within a component:</p>



<pre class="wp-block-code"><code>export async function getStaticProps(context) {
  return {
    props: {}, // will be passed to the page component as props
  }
}</code></pre>



<p class="wp-block-paragraph">Simple enough. What we have here is a simple function that can be exported from a React component built using Next. Now, let’s take a look at a simple component that utilizes this method:</p>



<pre class="wp-block-code"><code>const CoffeeList = ( {coffeeJson} ) =&gt; {
  return (
      &lt;div&gt;
          &lt;h1&gt;Coffee List&lt;/h1&gt;
              &lt;ul&gt;
                    {coffeeJson.length &gt; 0 ? coffeeJson.map((coffeeItem) =&gt; &lt;li&gt;{coffeeItem}&lt;/li&gt;) : "No coffee!"}
              &lt;/ul&gt;
        &lt;/div&gt;
  )
};

export default CoffeeList;

export async function getStaticProps() {
   const coffeeJson = await fetch('https://exampleapi.com/coffelist');
    return {
        props: {
            coffeeJson
        }
    }
}</code></pre>



<p class="wp-block-paragraph">Reviewing the code above, we have a `CoffeeList` component that displays a list of coffee items. It accepts a prop called “coffeeList” that contains the coffee list data. The coffeList prop was declared and populated in our <strong>getStaticProps() </strong>method.</p>



<p class="wp-block-paragraph">&nbsp;&nbsp;&nbsp; So, the <strong>getStaticProps() </strong>serves two purposes in this context.</p>



<ol class="wp-block-list">
<li>It tells the React framework to render this content at build time.</li>



<li>It populates the data object and sends it to the component as a prop.</li>
</ol>



<p class="wp-block-paragraph">Now that we’ve seen what it takes to utilize NextJs for creating an SSG page, let’s see what it takes to render real-time on the server.</p>



<h2 class="wp-block-heading" id="gspvsgssp-gssp-example">Code Examples of getServerSideProps</h2>



<p class="wp-block-paragraph">Using <strong>getServerSideProps </strong>for SSR is just as easy as utilizing the previous method for SSG. Here’s a raw example of this method straight from the <a href="https://nextjs.org/docs/basic-features/data-fetching/get-server-side-props">NextJs docs</a>:</p>



<pre class="wp-block-code"><code>export async function getServerSideProps(context) {
  return {
    props: {}, // will be passed to the page component as props
  }
}</code></pre>



<p class="wp-block-paragraph">Strikingly similar to our previous example using <strong>getStaticProps! </strong>In fact, the only difference is the name of the method itself. So, no need to show another full component example using <strong>getServerSideProps()</strong>, because the only thing needed to accomplish SSR instead of SSG is to change the name of your method to <strong>getServerSideProps().</strong></p>



<h2 class="wp-block-heading" id="gspvsgssp-overview">Overview and Conclusion</h2>



<p class="wp-block-paragraph">NextJs offers two ways to render a web page: as a static HTML page rendered at build time (SSG), or as a dynamically rendered page rendered at run time (SSR). These two techniques have huge implications regarding SEO, and it’s important to understand how to implement them using NextJs.</p>



<p class="wp-block-paragraph"><br>&nbsp;&nbsp;&nbsp; To statically render pages (also known as static site generation, or SSG) that load extremely fast on the client, and can be easily cached using a CDN provider to further increase performance, the <strong>getStaticProps() </strong>method should be exported from the Next component.&nbsp;</p>



<p class="wp-block-paragraph">Using<strong> getStaticProps() </strong>for SSG is the most optimal technique for generating performant SEO metrics, but is somewhat limited when used with pages that require frequently updated dynamic data.</p>



<p class="wp-block-paragraph">To render pages at each request (also known as server side rendering, or SSR) that load faster and more efficiently than typical SPAs, the <strong>getServerSideProps()</strong> method should be exported from the Next component.</p>



<p class="wp-block-paragraph">Using <strong>getServerSideProps()</strong> for SSR isn’t quite as optimal as SSG, but it still offers great SEO metrics and allows for extremely scalable pages that are heavily reliant on frequently changing dynamic data.</p>



<h2 class="wp-block-heading">Where to go from here?</h2>



<p class="wp-block-paragraph">When it comes to creating NextJs apps with performant SEO, it’s much like learning any other framework. The best way to learn is to dive in and create a practice project. We highly recommend heading over to the <a href="https://nextjs.org/docs/getting-started">getting-started</a> page at the NextJs docs to see what you can create!</p>
<p>The post <a href="https://www.ohmycrawl.com/nextjs/getstaticprops-vs-getserversideprops/">getStaticProps vs getServerSideProps for Next JS</a> appeared first on <a href="https://www.ohmycrawl.com">OhMyCrawl</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.ohmycrawl.com/nextjs/getstaticprops-vs-getserversideprops/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 

Served from: www.ohmycrawl.com @ 2026-10-22 17:01:29 by W3 Total Cache
-->