<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Saar Twito - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Saar Twito - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Wed, 25 Nov 2026 18:31:54 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/author/saar-twito/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Find and Fix Common Technical SEO Issues on Your Website ]]>
                </title>
                <description>
                    <![CDATA[ Let's say you've built a website. You've invested in the design, bought a domain, and so on. But a website isn't only what you see on the screen. A lot happens behind the scenes. You have to understan ]]>
                </description>
                <link>https://www.freecodecamp.org/news/fix-common-technical-seo-issues/</link>
                <guid isPermaLink="false">6aea2f4db1deb69c0283692a</guid>
                
                    <category>
                        <![CDATA[ SEO ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Beginner Developers ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Saar Twito ]]>
                </dc:creator>
                <pubDate>Tue, 03 Nov 2026 19:00:29 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/uploads/covers/5e1e335a7a1d3fcc59028c64/8d158690-136a-44a2-aa34-e24be77e004c.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Let's say you've built a website. You've invested in the design, bought a domain, and so on. But a website isn't only what you see on the screen. A lot happens behind the scenes. You have to understand how the internet works, as well as how Search Engine Optimization (SEO) works.</p>
<p>Speed is a key part of it, too. A slow site can have very weak SEO, because most people won't spend much time waiting for a page to load, especially these days.</p>
<p>Site speed is a well-known topic with many problems of its own to consider, like Largest Contentful Paint (LCP), Cumulative Layout Shift (CLS), and server speed. But I'll leave those for another article.</p>
<p>This one is about the problems that stop search engines from reaching and reading your pages.</p>
<p>In my opinion, technical SEO is much harder to apply than regular SEO, which focuses on content and keywords. The technical side usually requires a developer's knowledge, and might need some changes that can feel a bit uncomfortable if you don't have a technical background.</p>
<p>A technical problem can stay unnoticed for months, because you usually don't see it. It's not a design problem. You only find it when you run specific checks, for example with <a href="https://pagespeed.web.dev/">Google PageSpeed Insights</a>.</p>
<p>In this tutorial, you'll find and fix the most common ones on a small practice site. I didn't want to take a real website and shame its owners, so I built a practice site with the problems already in it.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><a href="#heading-prerequisites">Prerequisites</a></li>
<li><a href="#heading-what-is-technical-seo">What Is Technical SEO?</a></li>
<li><a href="#heading-how-common-are-these-problems-on-real-websites">How Common Are These Problems on Real Websites?</a></li>
<li><a href="#heading-how-to-set-up-the-practice-site">How to Set Up the Practice Site</a></li>
<li><a href="#heading-how-to-check-a-pages-http-status-code">How to Check a Page's HTTP Status Code</a><ul>
<li><a href="#heading-what-is-a-soft-404">What Is a Soft 404?</a></li>
</ul>
</li>
<li><a href="#heading-how-to-find-and-fix-redirect-chains">How to Find and Fix Redirect Chains</a></li>
<li><a href="#heading-how-to-make-sure-robotstxt-isnt-blocking-important-pages">How to Make Sure robots.txt Isn't Blocking Important Pages</a></li>
<li><a href="#heading-how-to-find-an-accidental-noindex">How to Find an Accidental noindex</a><ul>
<li><a href="#heading-how-to-check-the-robots-meta-tag">How to Check the Robots Meta Tag</a></li>
<li><a href="#heading-how-to-check-the-x-robots-tag-header">How to Check the X-Robots-Tag Header</a></li>
</ul>
</li>
<li><a href="#heading-how-to-use-canonical-tags-correctly">How to Use Canonical Tags Correctly</a></li>
<li><a href="#heading-how-to-fix-missing-and-duplicate-titles-and-meta-descriptions">How to Fix Missing and Duplicate Titles and Meta Descriptions</a></li>
<li><a href="#heading-how-to-make-your-links-crawlable">How to Make Your Links Crawlable</a></li>
<li><a href="#heading-how-to-check-whether-your-content-needs-javascript-to-appear">How to Check Whether Your Content Needs JavaScript to Appear</a></li>
<li><a href="#heading-can-you-check-a-page-in-five-minutes">Can You Check a Page in Five Minutes?</a></li>
<li><a href="#heading-conclusion">Conclusion</a></li>
</ul>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>You don't need to be an experienced programmer to follow along. You'll need:</p>
<ul>
<li>A web browser, such as Chrome, Firefox, Edge or Safari. In Safari, first turn on <strong>Show features for web developers</strong> under Settings &gt; Advanced.</li>
<li>A terminal: Terminal on macOS, PowerShell on Windows, or any terminal on Linux.</li>
<li><code>curl</code>, a small program that downloads web pages. It comes with macOS, most Linux distributions, and Windows 10 (version 1803 and later) and Windows 11.</li>
<li><a href="https://nodejs.org/">Node.js</a>, to run the practice site. The code was tested with Node.js 26.8 and curl 8.7.</li>
</ul>
<p>On Windows PowerShell, type <code>curl.exe</code> instead of <code>curl</code>, because there <code>curl</code> is a shortcut to a <a href="https://learn.microsoft.com/en-us/windows/curl/">different command</a>. Replace <code>| grep -i "text"</code> with <code>| Select-String "text"</code>, and <code>/dev/null</code> with <code>NUL</code>.</p>
<h2 id="heading-what-is-technical-seo">What Is Technical SEO?</h2>
<p>Google has programs called crawlers. They search the internet all the time for new websites and new pages. When Google discovers a new address, it may crawl the page and process what's on it (the text, images, and videos).</p>
<p>If Google decides the page is worth indexing, it may add it to a very big database of web pages, called the index. Google can then consider the pages in its index for its search results, when they're relevant to what someone searches for. Google's guide to <a href="https://developers.google.com/search/docs/fundamentals/how-search-works">how Search works</a> calls these three steps crawling, indexing, and serving.</p>
<p>So crawling doesn't guarantee indexing, and indexing doesn't guarantee a place in the results. The same guide says Google doesn't guarantee any of the three stages, even for a page that follows all of its rules.</p>
<p>Fixing technical problems won't necessarily make your site rank first on Google. But it does strengthen your chances of ranking higher, because every problem you fix makes your site better.</p>
<p>Technical SEO has to come together with regular SEO, like keywords, backlinks, engagement on social media, and so on.</p>
<h2 id="heading-how-common-are-these-problems-on-real-websites">How Common Are These Problems on Real Websites?</h2>
<p>The numbers below come from audits run with the site-auditing tool I build. Each website counts once, using its first audit, and this data comes from October 25th.</p>
<p>Crawls check many pages on one site (a median of 10 pages here). Single-page audits check one page, usually the home page.</p>
<table>
<thead>
<tr>
<th>Problem</th>
<th>How often</th>
<th>Sample</th>
</tr>
</thead>
<tbody><tr>
<td>At least one page with no canonical tag</td>
<td>64.2% of sites</td>
<td>53 crawled sites, Aug 2025 to Oct 2026</td>
</tr>
<tr>
<td>Two or more pages with exactly the same title</td>
<td>61.8% of sites</td>
<td>34 crawled sites with two or more pages that loaded</td>
</tr>
<tr>
<td>At least one page with no meta description</td>
<td>49.1% of sites</td>
<td>53 crawled sites</td>
</tr>
<tr>
<td>At least one link leading to a page that returns 404</td>
<td>18.9% of sites</td>
<td>53 crawled sites</td>
</tr>
<tr>
<td>Page built mostly with JavaScript</td>
<td>17.7% of pages</td>
<td>277 single-page audits, May to Oct 2026</td>
</tr>
<tr>
<td>At least one page with no title</td>
<td>13.2% of sites</td>
<td>53 crawled sites</td>
</tr>
<tr>
<td>A link that search engines may not be able to follow</td>
<td>8.3% of pages</td>
<td>278 single-page audits</td>
</tr>
<tr>
<td>A robots.txt file with errors, or one that failed to load</td>
<td>7.9% of sites</td>
<td>252 single-page audits, Jul to Oct 2026</td>
</tr>
<tr>
<td>Page blocked by noindex or by robots.txt</td>
<td>4.8% of pages</td>
<td>251 single-page audits, Jul to Oct 2026</td>
</tr>
</tbody></table>
<p>These are all technical problems, but they don't all weigh the same. Missing canonical tags are at the top, but Google doesn't require a canonical tag, so a page without one isn't broken by itself. It matters when the same or very similar content is reachable at more than one URL, as you'll see in the canonical section.</p>
<p>Duplicate titles are something I had myself: when you write code, it's easy to miss things like that. That's why there are tools that check for these problems.</p>
<p>Let's go over each issue in the table to make sure they're all clear:</p>
<ul>
<li><strong>Missing canonical tag:</strong> a canonical tag is basically one of the many tags you put in the <code>&lt;head&gt;</code> of your HTML. When two or three pages have pretty much the same content, it tells search engines like Google which URL is the original, main version, the one you prefer to get indexed. It's not required, though: without it, Google picks the main version itself, so it matters mostly for pages that have duplicates.</li>
<li><strong>Duplicate titles:</strong> it's really easy to end up with the same title on two pages. You don't want a duplicated title because it's not helpful and can confuse Google. Each page should say what it's about.</li>
<li><strong>Missing meta description:</strong> this one is really important, because it helps search engines as well as AI tools like ChatGPT. The meta description is there to explain very briefly what the page is about and what it's for. If you go to Google and search for a website, you'll see it under the actual link to the site.</li>
<li><strong>A link to a 404 page:</strong> this basically means you have a broken link (maybe a link you probably don't use anymore) to a page that isn't there. So there's no reason for it to lead to something that doesn't exist. Use it to lead to something similar, or to something that does exist, so your links remain relevant.</li>
<li><strong>A page built mostly with JavaScript:</strong> Google can run JavaScript, so this alone doesn't keep a page out of Google. But the content appears only after the JavaScript loads and runs, which is slower for visitors and one more step that can fail, and not every crawler runs JS. That's why I prefer <a href="https://www.freecodecamp.org/news/server-side-rendering-in-next-js-for-improved-seo/">server-side rendering</a> for the content that matters most.</li>
<li><strong>A link search engines can't follow:</strong> this isn't a huge deal, and it really depends where the link goes. But say I wrote a really nice article and I want it to help me rank on Google. If search engines can't follow the link to it, then you invested all this time and energy in this article that relatively few people will likely see.</li>
<li><strong>Errors in robots.txt:</strong> robots.txt basically helps you talk to search engines. If there are errors in this file, you might stop search engines from crawling pages you do want in search results.</li>
<li><strong>A page blocked by noindex or robots.txt:</strong> these are two different things. A <code>noindex</code> rule asks search engines to keep a page out of their results, while a robots.txt rule only stops them from crawling it. You'll learn more about both, and why the difference matters, later in this tutorial.</li>
</ul>
<p>Soft 404s, redirect chains, and wrong canonical tags aren't in the table, because the audits don't record them.</p>
<h2 id="heading-how-to-set-up-the-practice-site">How to Set Up the Practice Site</h2>
<p>The practice site is a tiny website for a made-up shoe store called Acme Shoes. Every page on it has one problem built in. You don't need to understand every line of the code.</p>
<p>Create a new folder, add a file called <code>server.js</code>, and paste in this code:</p>
<pre><code class="language-javascript">// server.js: a tiny practice site with common technical SEO problems built in
const http = require('node:http');

const PORT = 8080;
const BASE = 'http://localhost:' + PORT;

// Builds a simple HTML page. Leave out a field to leave that tag out.
function page({ title, description, canonical, robots, body, script }) {
  return [
    '&lt;!doctype html&gt;',
    '&lt;html lang="en"&gt;',
    '&lt;head&gt;',
    '&lt;meta charset="utf-8"&gt;',
    title &amp;&amp; '&lt;title&gt;' + title + '&lt;/title&gt;',
    description &amp;&amp; '&lt;meta name="description" content="' + description + '"&gt;',
    canonical &amp;&amp; '&lt;link rel="canonical" href="' + BASE + canonical + '"&gt;',
    robots &amp;&amp; '&lt;meta name="robots" content="' + robots + '"&gt;',
    '&lt;/head&gt;',
    '&lt;body&gt;',
    body,
    script &amp;&amp; '&lt;script&gt;' + script + '&lt;/script&gt;',
    '&lt;/body&gt;',
    '&lt;/html&gt;',
  ]
    .filter(Boolean)
    .join('\n');
}

const routes = {
  '/': {
    html: page({
      title: 'Acme Shoes: Running Shoes for Every Runner',
      description: 'Lightweight running shoes for road and trail, with free returns.',
      canonical: '/',
      body: [
        '&lt;h1&gt;Acme Shoes&lt;/h1&gt;',
        '&lt;a href="/products/blue-runner"&gt;Blue Runner&lt;/a&gt;',
        '&lt;span onclick="location.href=\'/sale\'"&gt;Summer sale&lt;/span&gt;',
      ].join('\n'),
    }),
  },
  // Problem: a vague title and no meta description
  '/products/blue-runner': {
    html: page({
      title: 'Acme Shoes',
      canonical: '/products/blue-runner',
      body: '&lt;h1&gt;Blue Runner&lt;/h1&gt;',
    }),
  },
  // Problem: a missing product that still answers "200 OK" (a soft 404)
  '/products/red-runner': {
    html: page({
      title: 'Acme Shoes',
      body: '&lt;h1&gt;Sorry, that product could not be found.&lt;/h1&gt;',
    }),
  },
  // Problem: a redirect chain, /old-sale -&gt; /sale-2025 -&gt; /sale
  '/old-sale': { redirect: '/sale-2025' },
  '/sale-2025': { redirect: '/sale' },
  '/sale': {
    html: page({
      title: 'Summer Sale: Up to 40% Off Running Shoes | Acme Shoes',
      description: "Save up to 40% on last season's running shoes until August 31.",
      canonical: '/sale',
      body: '&lt;h1&gt;Summer sale&lt;/h1&gt;',
    }),
  },
  // Problem: a noindex header nobody can see in the page itself
  '/about': {
    headers: { 'X-Robots-Tag': 'noindex' },
    html: page({
      title: 'About Acme Shoes',
      description: 'How a two-person workshop became a running shoe brand.',
      canonical: '/about',
      body: '&lt;h1&gt;About us&lt;/h1&gt;',
    }),
  },
  // Problem: a canonical tag that points to the home page
  '/blog/choosing-trail-shoes': {
    html: page({
      title: 'How to Choose Trail Running Shoes | Acme Shoes',
      description: 'Grip, drop and fit: what to look for in a trail running shoe.',
      canonical: '/',
      body: '&lt;h1&gt;How to choose trail running shoes&lt;/h1&gt;',
    }),
  },
  // Problem: the content only exists after JavaScript runs
  '/catalog': {
    html: page({
      title: 'All Running Shoes | Acme Shoes',
      description: 'Browse every Acme running shoe.',
      canonical: '/catalog',
      body: '&lt;div id="app"&gt;Loading...&lt;/div&gt;',
      script:
        "fetch('/api/products').then((r) =&gt; r.json()).then((products) =&gt; {" +
        "document.getElementById('app').innerHTML = products.map((p) =&gt; '&lt;h2&gt;' + p + '&lt;/h2&gt;').join('');" +
        '});',
    }),
  },
  '/api/products': {
    type: 'application/json',
    html: JSON.stringify(['Blue Runner', 'Trail Grip 2', 'City Glide']),
  },
  // Problem: "Disallow: /blog" blocks every path that starts with /blog
  '/robots.txt': {
    type: 'text/plain',
    html: 'User-agent: *\nDisallow: /blog\n',
  },
};

http
  .createServer((req, res) =&gt; {
    const path = new URL(req.url, BASE).pathname;
    const route = routes[path];

    if (!route) {
      res.writeHead(404, { 'Content-Type': 'text/html; charset=utf-8' });
      return res.end(page({ title: 'Page not found', body: '&lt;h1&gt;Page not found&lt;/h1&gt;' }));
    }
    if (route.redirect) {
      res.writeHead(301, { Location: route.redirect });
      return res.end();
    }
    res.writeHead(200, {
      'Content-Type': (route.type || 'text/html') + '; charset=utf-8',
      ...route.headers,
    });
    res.end(route.html);
  })
  .listen(PORT, () =&gt; console.log('Practice site running at ' + BASE));
</code></pre>
<p>Each key in <code>routes</code> is a page address. The comments that start with <code>Problem:</code> say what's wrong with each page.</p>
<p>Start the server from the same folder:</p>
<pre><code class="language-bash">node server.js
</code></pre>
<p>You should see:</p>
<pre><code class="language-text">Practice site running at http://localhost:8080
</code></pre>
<p>Leave the server running and open a second terminal for the commands below. When you change <code>server.js</code>, stop the server with Ctrl+C and start it again.</p>
<h2 id="heading-how-to-check-a-pages-http-status-code">How to Check a Page's HTTP Status Code</h2>
<p>I remember when I started building websites, I built all kinds of small things. I'm a full stack developer, and I kept trying experiments.</p>
<p>Once I had a problem on the server side and saw in the Network tab that it returned a 500 error. Another time I removed a page on purpose, because I wanted to see if I'd get a 404 or other problems. If you just play around with the site you're building, you'll learn a lot from the results.</p>
<p>HTTP status codes are the first thing a search engine reads. They're the server's way of talking to the client, such as your browser. The codes are split into five ranges: 1xx, 2xx, 3xx, 4xx, and 5xx. A 5xx code is a server problem, for example, and a 4xx code is a client-side problem.</p>
<p>404 is the most common error. It means a page on the site wasn't found. You see 404s all the time, and the fix is typically just to maintain your site and your links.</p>
<p>The codes you'll see in this tutorial are:</p>
<ul>
<li><code>200 OK</code>: here's the page.</li>
<li><code>301 Moved Permanently</code>: the page lives at another address.</li>
<li><code>404 Not Found</code>: there's no page here.</li>
</ul>
<p>Google doesn't index URLs that return a <code>4xx</code> code, according to its documentation on <a href="https://developers.google.com/search/docs/crawling-indexing/http-network-errors">HTTP status codes</a>.</p>
<p>To see the status code of the practice site's home page, use <code>-I</code>, which shows only the headers, and <code>-s</code>, which hides curl's progress meter:</p>
<pre><code class="language-bash">curl -sI http://localhost:8080/
</code></pre>
<pre><code class="language-text">HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Date: Sun, 25 Oct 2026 17:42:53 GMT
Connection: keep-alive
Keep-Alive: timeout=5
</code></pre>
<p>Now ask for an address that isn't in <code>routes</code>, to see what a correct 404 looks like:</p>
<pre><code class="language-bash">curl -sI http://localhost:8080/products/does-not-exist
</code></pre>
<pre><code class="language-text">HTTP/1.1 404 Not Found
Content-Type: text/html; charset=utf-8
Date: Sun, 25 Oct 2026 17:42:53 GMT
Connection: keep-alive
Keep-Alive: timeout=5
</code></pre>
<p>In the browser, open the developer tools (F12, or Cmd+Option+I on a Mac), go to the <strong>Network</strong> tab, and reload. The <strong>Status</strong> column shows the code.</p>
<h3 id="heading-what-is-a-soft-404">What Is a Soft 404?</h3>
<p>Check a product the store no longer sells:</p>
<pre><code class="language-bash">curl -sI http://localhost:8080/products/red-runner
</code></pre>
<pre><code class="language-text">HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Date: Sun, 25 Oct 2026 17:42:53 GMT
Connection: keep-alive
Keep-Alive: timeout=5
</code></pre>
<p>In the browser, the same page says "Sorry, that product could not be found."</p>
<p>A soft 404 is basically a "page not found", but the server still answers <code>200</code>. It confuses Google, because the address is still there, but what's on it isn't current anymore.</p>
<p>To fix it, make missing pages return a real <code>404</code>, which is what <a href="https://support.google.com/webmasters/answer/7440203">Google recommends</a>. In the practice site, delete the <code>'/products/red-runner'</code> entry from <code>routes</code>. The server then answers <code>404</code>.</p>
<p>Broken links lead to the same dead end. In the data, 18.9% of the 53 crawled sites had at least one link to a page that returned <code>404</code>.</p>
<p>So don't leave links that lead to something that doesn't exist. Update them to lead to something similar, or to something that does exist.</p>
<p>If the page moved, add a <code>301</code> redirect from the old address to the new one. A <code>404</code> is the right answer only for a page that's really gone.</p>
<h2 id="heading-how-to-find-and-fix-redirect-chains">How to Find and Fix Redirect Chains</h2>
<p>A redirect is basically when you want to send one URL (perhaps one that no longer exists) to another URL (that does exist). You might set up a redirect if, for example, you change your domain from <code>example-x.com</code> to <code>example-y.com</code>. You'll want everyone who types <code>example-x.com</code> to be redirected to <code>example-y.com</code> automatically.</p>
<p>Redirects are fine, and they can be quite helpful when used properly. A <code>301</code> means the page moved for good. A <code>302</code> means the move is temporary. Google's documentation on <a href="https://developers.google.com/search/docs/crawling-indexing/301-redirects">redirects</a> explains how it treats each one, and its crawlers <a href="https://developers.google.com/search/docs/crawling-indexing/http-network-errors">follow up to 10 redirect hops</a>.</p>
<p>But a redirect chain happens when an old address, such as a domain you used in the past, redirects to a new one, and then that one redirects again, and again...you get the picture. A few redirects aren't a big deal, but five, six, or seven can be a real problem.</p>
<p>The first command below shows every step of the chain. The second gives you a one-line summary.</p>
<p>Add <code>-L</code> so curl follows the redirects:</p>
<pre><code class="language-bash">curl -sIL http://localhost:8080/old-sale
</code></pre>
<pre><code class="language-text">HTTP/1.1 301 Moved Permanently
Location: /sale-2025
Date: Sun, 25 Oct 2026 17:42:53 GMT
Connection: keep-alive
Keep-Alive: timeout=5

HTTP/1.1 301 Moved Permanently
Location: /sale
Date: Sun, 25 Oct 2026 17:42:53 GMT
Connection: keep-alive
Keep-Alive: timeout=5

HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Date: Sun, 25 Oct 2026 17:42:53 GMT
Connection: keep-alive
Keep-Alive: timeout=5
</code></pre>
<p><code>/old-sale</code> goes to <code>/sale-2025</code>, which goes to <code>/sale</code>. For a one-line summary:</p>
<pre><code class="language-bash">curl -sL -o /dev/null -w "%{num_redirects} redirects, ended at %{url_effective}\n" http://localhost:8080/old-sale
</code></pre>
<pre><code class="language-text">2 redirects, ended at http://localhost:8080/sale
</code></pre>
<p><code>-o /dev/null</code> tells curl to write the page's HTML nowhere, so it doesn't fill your terminal and only the summary line is printed. <code>-w</code> sets what that summary line says.</p>
<p>To fix it, point the old/original address straight at the final page:</p>
<pre><code class="language-javascript">'/old-sale': { redirect: '/sale' },
</code></pre>
<p>Restart the server and run the summary again. It now says <code>1 redirects, ended at http://localhost:8080/sale</code>.</p>
<h2 id="heading-how-to-make-sure-robotstxt-isnt-blocking-important-pages">How to Make Sure robots.txt Isn't Blocking Important Pages</h2>
<p>robots.txt is the site's way of telling search engines like Google (and their crawlers) what they're allowed to explore and where they have access.</p>
<p>Look at the practice site's file:</p>
<pre><code class="language-bash">curl -s http://localhost:8080/robots.txt
</code></pre>
<pre><code class="language-text">User-agent: *
Disallow: /blog
</code></pre>
<p><code>Disallow: /blog</code> is dangerous because it stops crawlers from reading every path that starts with <code>/blog</code>. And usually, your articles are what promote your site the most.</p>
<p>Google's <a href="https://developers.google.com/search/docs/crawling-indexing/robots/robots_txt">robots.txt documentation</a> gives the same kind of example: <code>Disallow: /fish</code> also blocks <code>/fish.html</code> and <code>/fishheads</code>.</p>
<p>To fix it, make the rule match only what you meant to block, for example a folder of drafts:</p>
<pre><code class="language-text">User-agent: *
Disallow: /blog-drafts/
</code></pre>
<p>In the practice site, change the <code>html</code> line of the <code>'/robots.txt'</code> entry:</p>
<pre><code class="language-javascript">html: 'User-agent: *\nDisallow: /blog-drafts/\n',
</code></pre>
<p>robots.txt controls crawling, not indexing. Google says it's <a href="https://developers.google.com/search/docs/crawling-indexing/robots/intro">not a mechanism for keeping a page out of Google</a>. For that, you need <code>noindex</code>.</p>
<p>A URL blocked in robots.txt can even appear in search results, usually without a description, if other pages link to it. Google just never reads what's on the page.</p>
<h2 id="heading-how-to-find-an-accidental-noindex">How to Find an Accidental noindex</h2>
<p><code>noindex</code> tells Google not to index a particular page. It's harmful when it ends up on pages you do want indexed and ranked, like a product page or your home page.</p>
<p>But it can be useful on pages you don't need to rank for, or that don't add much to the site, such as log in, sign in, and sign up pages.</p>
<p><code>noindex</code> works only when the crawler can reach the page and read the rule. If robots.txt blocks the same URL, Google never sees the <code>noindex</code>, and the page can still show up in search results. So for a page you want out of Google, use <code>noindex</code> and leave the page crawlable.</p>
<p>In the data, 11 of 457 audited pages (2.4%) had a <code>noindex</code> robots meta tag. There are <a href="https://developers.google.com/search/docs/crawling-indexing/block-indexing">two ways to set it</a>, and you need to check both.</p>
<h3 id="heading-how-to-check-the-robots-meta-tag">How to Check the Robots Meta Tag</h3>
<p>The first way is a tag in the page's <code>&lt;head&gt;</code>:</p>
<pre><code class="language-html">&lt;meta name="robots" content="noindex"&gt;
</code></pre>
<p>Search the page for the word:</p>
<pre><code class="language-bash">curl -s http://localhost:8080/about | grep -i noindex
</code></pre>
<p>On the About page, this prints nothing. You can also right-click the page, choose <strong>View Page Source,</strong> and search for <code>noindex</code>.</p>
<p>Fixing a noindex is really easy. You basically remove it, and then search engines can index the page.</p>
<p>Look for it in the page's code or template, and in your CMS or SEO plugin settings. In WordPress, the setting <strong>Discourage search engines from indexing this site</strong> adds it to every page.</p>
<h3 id="heading-how-to-check-the-x-robots-tag-header">How to Check the X-Robots-Tag Header</h3>
<p>The second way is an HTTP header. Check the About page's headers:</p>
<pre><code class="language-bash">curl -sI http://localhost:8080/about
</code></pre>
<pre><code class="language-text">HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
X-Robots-Tag: noindex
Date: Sun, 25 Oct 2026 17:42:59 GMT
Connection: keep-alive
Keep-Alive: timeout=5
</code></pre>
<p>The header doesn't appear in View Page Source, only in the response headers. In the data, 5 of the 12 blocked pages had no <code>noindex</code> in their HTML: 2 had this header, and 3 were blocked from crawling by robots.txt.</p>
<p>To fix it in the practice site, delete the <code>headers</code> line from the <code>'/about'</code> entry. On a real site, check the server configuration, the hosting provider's header settings, and any SEO plugin.</p>
<h2 id="heading-how-to-use-canonical-tags-correctly">How to Use Canonical Tags Correctly</h2>
<p>If you have several pages that talk about more or less the same thing, but without enough meat to be different, you want to designate one main page. The canonical tag tells search engines which page that is.</p>
<p>The same page can also live at several addresses:</p>
<pre><code class="language-text">https://example.com/blog/choosing-trail-shoes
https://example.com/blog/choosing-trail-shoes?utm_source=newsletter
https://www.example.com/blog/choosing-trail-shoes
</code></pre>
<p>These three addresses show the same article. The first one is the main one: the address you want Google to show in search results. So all three carry the same canonical tag, pointing to that main page:</p>
<pre><code class="language-html">&lt;link rel="canonical" href="https://example.com/blog/choosing-trail-shoes"&gt;
</code></pre>
<p>When Google sees this tag on the <code>?utm_source=newsletter</code> version, it knows that page is a copy of the first address. The main address carries the same tag, pointing to itself. That's called a self-referencing canonical, and it says: I'm the main version.</p>
<p>Google treats it as a <a href="https://developers.google.com/search/docs/crawling-indexing/consolidate-duplicate-urls">strong signal, not a command</a>. If you use canonical tags, a self-referencing one on each main page is a good practice, and Google recommends it.</p>
<p>But you don't have to use canonical tags at all. Google says specifying a canonical isn't required: without one, it picks the version it thinks is best to show users. A canonical tag is a good choice when the same or very similar content is reachable at more than one URL, like the three addresses above.</p>
<p>That's why a missing canonical tag isn't a defect by itself. In the data, 27.1% of 457 audited pages had no canonical tag. What matters is whether any of them have duplicates, like a version with tracking parameters, that need one.</p>
<p>Check the practice site's trail shoe article:</p>
<pre><code class="language-bash">curl -s http://localhost:8080/blog/choosing-trail-shoes | grep -i canonical
</code></pre>
<pre><code class="language-text">&lt;link rel="canonical" href="http://localhost:8080/"&gt;
</code></pre>
<p>The article says its main version is the home page, so Google may show the home page instead of it, or ignore the tag.</p>
<p>The article isn't a copy of anything, so it's its own main version. To fix it, point the article's canonical tag to the article itself:</p>
<pre><code class="language-javascript">canonical: '/blog/choosing-trail-shoes',
</code></pre>
<h2 id="heading-how-to-fix-missing-and-duplicate-titles-and-meta-descriptions">How to Fix Missing and Duplicate Titles and Meta Descriptions</h2>
<p>A good title or meta description is the right length, isn't overloaded, and says briefly what the page is about. It's sort of the essence of the page, like its introduction.</p>
<p>Look at the Blue Runner product page:</p>
<pre><code class="language-bash">curl -s http://localhost:8080/products/blue-runner | grep -i -E "&lt;title&gt;|name=\"description\""
</code></pre>
<pre><code class="language-text">&lt;title&gt;Acme Shoes&lt;/title&gt;
</code></pre>
<p>The title says nothing about the page, and there's no description line at all. In PowerShell, use <code>| Select-String '&lt;title&gt;|name="description"'</code> for this one.</p>
<p>Google's guides to <a href="https://developers.google.com/search/docs/appearance/title-link">titles</a> and <a href="https://developers.google.com/search/docs/appearance/snippet">snippets</a> ask for a unique, descriptive title and description on every page.</p>
<p>To fix it in the practice site, replace the <code>title</code> line of the <code>'/products/blue-runner'</code> entry with:</p>
<pre><code class="language-javascript">title: 'Blue Runner Road Running Shoe | Acme Shoes',
description: 'A lightweight road running shoe with a cushioned sole and free returns.',
</code></pre>
<h2 id="heading-how-to-make-your-links-crawlable">How to Make Your Links Crawlable</h2>
<p>Look at the practice site's home page:</p>
<pre><code class="language-bash">curl -s http://localhost:8080/
</code></pre>
<pre><code class="language-text">&lt;!doctype html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta charset="utf-8"&gt;
&lt;title&gt;Acme Shoes: Running Shoes for Every Runner&lt;/title&gt;
&lt;meta name="description" content="Lightweight running shoes for road and trail, with free returns."&gt;
&lt;link rel="canonical" href="http://localhost:8080/"&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Acme Shoes&lt;/h1&gt;
&lt;a href="/products/blue-runner"&gt;Blue Runner&lt;/a&gt;
&lt;span onclick="location.href='/sale'"&gt;Summer sale&lt;/span&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>Everything else on this page is fine: the title, the description, the canonical tag and the Blue Runner link, which is a real <code>&lt;a&gt;</code> element with an <code>href</code>. The only problem is the "Summer sale" <code>&lt;span&gt;</code>.</p>
<p>A <code>&lt;span&gt;</code> is basically HTML that isn't semantic, meaning it has no meaning. A real link does have meaning: search engines can understand it's a link, and screen readers can understand it's a link.</p>
<p>Which links need to be crawlable? Basically, everything you want search engines to see. I mean the products you sell, your articles, your courses, and other things like that.</p>
<p>Google's <a href="https://developers.google.com/search/docs/crawling-indexing/links-crawlable">link guidelines</a> say it can only reliably crawl an <code>&lt;a&gt;</code> element with an <code>href</code>.</p>
<p>To fix it in the practice site, replace the <code>&lt;span&gt;</code> line with:</p>
<pre><code class="language-javascript">'&lt;a href="/sale"&gt;Summer sale&lt;/a&gt;',
</code></pre>
<h2 id="heading-how-to-check-whether-your-content-needs-javascript-to-appear">How to Check Whether Your Content Needs JavaScript to Appear</h2>
<p>With client-side rendering, the JavaScript has to load first, and only then can the other content load.</p>
<p>JavaScript usually builds things like product lists, prices, reviews and menus. Without it, a client-side page often shows only a loading message or an empty box.</p>
<p>Google does render JavaScript, but <a href="https://developers.google.com/search/docs/crawling-indexing/javascript/javascript-seo-basics">in a later phase</a>. The page waits in a rendering queue, which can take a few seconds or longer, and a script that fails or is blocked can leave the rendered page without its content.</p>
<p>That's why server-side rendering is still a good idea, and it's what I prefer for the content that matters. Google's JavaScript guide says the same: server-side rendering makes the site faster for users and crawlers, and not all bots can run JavaScript.</p>
<p>In the data, 17.7% of 277 audited pages were built mostly with JavaScript. That doesn't mean Google couldn't index them, only that their main content depended on JavaScript running correctly.</p>
<p>With server-side rendering, the HTML content comes straight to the browser, and only after that does the JavaScript render.</p>
<p>Google can index pages built either way. Its crawler runs JavaScript with an up-to-date version of Chrome, so server-side rendering isn't a requirement for getting into Google's index.</p>
<p>The next test checks whether the important content is visible without JavaScript. It doesn't show what Google sees, because Google runs the JavaScript, but it shows what every crawler gets before any JavaScript runs.</p>
<p>Open <code>http://localhost:8080/catalog</code> in your browser. You'll see three products. Now download it with curl, which doesn't run JavaScript:</p>
<pre><code class="language-bash">curl -s http://localhost:8080/catalog | grep -i "trail grip"
</code></pre>
<p>This prints nothing, because the product names aren't in the HTML the server sends. Inside <code>&lt;body&gt;</code>, the server only sends:</p>
<pre><code class="language-html">&lt;div id="app"&gt;Loading...&lt;/div&gt;
&lt;script&gt;fetch('/api/products').then((r) =&gt; r.json()).then((products) =&gt; {document.getElementById('app').innerHTML = products.map((p) =&gt; '&lt;h2&gt;' + p + '&lt;/h2&gt;').join('');});&lt;/script&gt;
</code></pre>
<p>Without curl, use <strong>View Page Source</strong> in your browser. On this page, you'll see "Loading..." and the script, but none of the product names, because the browser adds them only after the JavaScript runs.</p>
<p>On your own site, search the source for an important sentence from the page.</p>
<p>To see the page the way Google renders it, use Google's own tools on a live page. On your own site, the URL Inspection tool in Search Console can run a live test (<strong>Test live URL</strong>, then <strong>View tested page</strong>) and show the HTML Google rendered and a screenshot.</p>
<p>For any public page, the <a href="https://search.google.com/test/rich-results">Rich Results Test</a> shows the rendered HTML too. Google <a href="https://developers.google.com/search/docs/crawling-indexing/javascript/fix-search-javascript">recommends both</a> for finding JavaScript problems. Neither can reach <code>localhost</code>, so try them on your real site.</p>
<p>If you want the product names in the HTML from the start, render them on the server. In the practice site, add the product list above <code>routes</code>:</p>
<pre><code class="language-javascript">const products = ['Blue Runner', 'Trail Grip 2', 'City Glide'];
</code></pre>
<p>Replace the catalog's <code>body</code> and <code>script</code> lines with:</p>
<pre><code class="language-javascript">body: '&lt;div id="app"&gt;' + products.map((p) =&gt; '&lt;h2&gt;' + p + '&lt;/h2&gt;').join('') + '&lt;/div&gt;',
</code></pre>
<p>And in the <code>'/api/products'</code> entry:</p>
<pre><code class="language-javascript">html: JSON.stringify(products),
</code></pre>
<p>Restart the server and run the curl command again:</p>
<pre><code class="language-text">&lt;div id="app"&gt;&lt;h2&gt;Blue Runner&lt;/h2&gt;&lt;h2&gt;Trail Grip 2&lt;/h2&gt;&lt;h2&gt;City Glide&lt;/h2&gt;&lt;/div&gt;
</code></pre>
<p>This works because the server now writes the product names into the HTML before it sends the page. Any crawler sees them, even one that can't run JavaScript, and you can still use JavaScript for the interactive parts.</p>
<h2 id="heading-can-you-check-a-page-in-five-minutes">Can You Check a Page in Five Minutes?</h2>
<p>Honestly, it's very hard. There can be a lot of problems, and five minutes isn't enough.</p>
<p>To really know what the problems are, you need to run a full check, for example in Google PageSpeed Insights. If the site is yours, also use the <a href="https://support.google.com/webmasters/answer/9012289">URL Inspection tool</a> in Google Search Console.</p>
<p>The commands from this tutorial are a good start:</p>
<ol>
<li><code>curl -sI</code> for the status code and an <code>X-Robots-Tag</code> header.</li>
<li><code>curl -sIL</code> on an old address to count redirects.</li>
<li><code>/robots.txt</code>, line by line.</li>
<li>View Page Source for <code>noindex</code>, <code>canonical</code>, <code>&lt;title&gt;</code>, <code>description</code> and your important content.</li>
</ol>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this tutorial, you fixed eight problems on a practice site: a soft 404, a redirect chain, a robots.txt rule, a hidden <code>noindex</code> header, a wrong canonical tag, a vague title and a missing description, a link crawlers couldn't follow, and content that needed JavaScript.</p>
<p>The most important thing to remember is that you'll need to check your site all the time. Run scans, do maintenance, and make sure nothing breaks, especially when you make improvements or changes to the site.</p>
<p>If you want to go further, my tutorial on <a href="https://www.freecodecamp.org/news/nextjs-json-ld-structured-data/">adding structured data (JSON-LD) to a Next.js site</a> is a good next step.</p>
<p>If you'd like to check a live page for many of these issues in one go, my free tool <a href="https://www.greadme.com/page-audit">Greadme Page Audit</a> tests any URL with no sign-up needed.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Add Structured Data (JSON-LD) to a Next.js Site and Validate It ]]>
                </title>
                <description>
                    <![CDATA[ Structured data has always mattered to search engines. When a search engine reads your page, it sees HTML: a heading, some paragraphs, a date somewhere, a name somewhere else. Structured data tells it ]]>
                </description>
                <link>https://www.freecodecamp.org/news/nextjs-json-ld-structured-data/</link>
                <guid isPermaLink="false">6acb575a7dfd7348cce66960</guid>
                
                    <category>
                        <![CDATA[ Next.js ]]>
                    </category>
                
                    <category>
                        <![CDATA[ SEO ]]>
                    </category>
                
                    <category>
                        <![CDATA[ TypeScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Saar Twito ]]>
                </dc:creator>
                <pubDate>Sun, 11 Oct 2026 09:31:06 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/uploads/covers/5e1e335a7a1d3fcc59028c64/4e937052-66b6-461f-ae80-53e8395811e8.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Structured data has always mattered to search engines. When a search engine reads your page, it sees HTML: a heading, some paragraphs, a date somewhere, a name somewhere else.</p>
<p>Structured data tells it directly what those pieces are. This page is an article, this is its headline, this person wrote it, and it was published on this date.</p>
<p>For me, search engine optimization isn't a box to tick at the end. I want the products and sites I build to be found, and to be understood correctly when they are.</p>
<p>That's why I add structured data to every page where it makes sense. And I think it's becoming more relevant, not less, as AI systems start answering questions from web content.</p>
<p>In a Next.js app, nothing writes that data for you. You add it yourself, as a small block of JSON in the pages that need it.</p>
<p>In this tutorial, you'll learn what structured data is and how JSON-LD works. Then you'll add it to a Next.js App Router project: a reusable <code>JsonLd</code> component that's safe to use with any data, organization and article data built from the same content the page renders, and a check that validates all of it after every build.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><p><a href="#heading-prerequisites">Prerequisites</a></p>
</li>
<li><p><a href="#heading-structured-data-basics-for-developers">Structured Data Basics for Developers</a></p>
<ul>
<li><p><a href="#heading-what-structured-data-and-json-ld-are">What Structured Data and JSON-LD Are</a></p>
</li>
<li><p><a href="#heading-how-a-json-ld-block-is-built">How a JSON-LD Block Is Built</a></p>
</li>
<li><p><a href="#heading-structured-data-json-ld-schemaorg-and-rich-results">Structured Data, JSON-LD, Schema.org and Rich Results</a></p>
</li>
<li><p><a href="#heading-what-structured-data-does-for-search-and-what-it-doesnt">What Structured Data Does for Search (and What It Doesn't)</a></p>
</li>
</ul>
</li>
<li><p><a href="#heading-how-to-build-a-safe-jsonld-component">How to Build a Safe JsonLd Component</a></p>
<ul>
<li><p><a href="#heading-why-not-nextscript">Why Not next/script</a></p>
</li>
<li><p><a href="#heading-why-the-escape-matters">Why the Escape Matters</a></p>
</li>
<li><p><a href="#heading-why-one-component">Why One Component</a></p>
</li>
</ul>
</li>
<li><p><a href="#heading-how-to-add-organization-and-website-data-to-the-home-page">How to Add Organization and WebSite Data to the Home Page</a></p>
</li>
<li><p><a href="#heading-how-to-add-article-and-breadcrumb-data-to-a-dynamic-route">How to Add Article and Breadcrumb Data to a Dynamic Route</a></p>
</li>
<li><p><a href="#heading-how-to-validate-your-structured-data">How to Validate Your Structured Data</a></p>
<ul>
<li><p><a href="#heading-check-what-actually-lands-in-the-html">Check What Actually Lands in the HTML</a></p>
</li>
<li><p><a href="#heading-use-the-online-validators">Use the Online Validators</a></p>
</li>
</ul>
</li>
<li><p><a href="#heading-how-to-validate-json-ld-automatically-after-every-build">How to Validate JSON-LD Automatically After Every Build</a></p>
</li>
<li><p><a href="#heading-conclusion">Conclusion</a></p>
</li>
</ul>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>To follow along, you'll need:</p>
<ul>
<li><p>A Next.js app that uses the App Router and TypeScript. The code in this article was tested with Next.js 16.4.0 and React 19.3.</p>
</li>
<li><p>Basic familiarity with Server Components and dynamic routes.</p>
</li>
<li><p>The <code>schema-dts</code> package, which gives you TypeScript types for structured data.</p>
</li>
</ul>
<p>Install <code>schema-dts</code> as a development dependency, since it only provides types:</p>
<pre><code class="language-bash">npm install -D schema-dts
</code></pre>
<p>The examples use a blog. Wherever you see <code>getPost()</code>, use your own data source: a CMS, a database, or Markdown files.</p>
<h2 id="heading-structured-data-basics-for-developers">Structured Data Basics for Developers</h2>
<p>If you've never worked with structured data, this section gives you just enough to understand the code that follows.</p>
<h3 id="heading-what-structured-data-and-json-ld-are">What Structured Data and JSON-LD Are</h3>
<p>Structured data is a machine-readable description of what a page is about. Instead of leaving a search engine to work out that "Jane Doe" is the author and "2026-09-01" is the publication date, you state it in a format a program can read without guessing.</p>
<p>The words you use come from <a href="https://schema.org/">Schema.org</a>, a shared vocabulary of types (like <code>Article</code>, <code>Person</code> and <code>Organization</code>) and their properties (like <code>headline</code>, <code>author</code> and <code>datePublished</code>). It was started by Google, Microsoft, Yahoo and Yandex, and it's the vocabulary search engines expect.</p>
<p>JSON-LD (JavaScript Object Notation for Linked Data) is one way to write that data. It's a <a href="https://www.w3.org/TR/json-ld11/">W3C standard</a>, and on a web page it lives in a script tag with its own type:</p>
<pre><code class="language-html">&lt;script type="application/ld+json"&gt;
  { "@context": "https://schema.org", "@type": "Article", "headline": "..." }
&lt;/script&gt;
</code></pre>
<p>The browser doesn't run this script. A type that isn't JavaScript turns the tag into what the <a href="https://html.spec.whatwg.org/multipage/scripting.html#data-block">HTML standard</a> calls a data block, "not processed by the user agent, but instead by author script or other tools."</p>
<p>There are two other formats, Microdata and RDFa, which add attributes to your existing HTML elements. Google supports all three, but it <a href="https://developers.google.com/search/docs/appearance/structured-data/intro-structured-data">recommends JSON-LD</a> "if your site's setup allows it." For a React developer, JSON-LD is also the natural fit: it's a plain object you build from data, separate from the JSX that renders the page.</p>
<h3 id="heading-how-a-json-ld-block-is-built">How a JSON-LD Block Is Built</h3>
<p>Here's a JSON-LD block for a blog post:</p>
<pre><code class="language-json">{
  "@context": "https://schema.org",
  "@type": "BlogPosting",
  "headline": "How Caching Works in Next.js",
  "datePublished": "2026-09-01T09:00:00.000Z",
  "author": {
    "@type": "Person",
    "name": "Jane Doe"
  },
  "publisher": {
    "@type": "Organization",
    "@id": "https://example.com/#organization",
    "name": "Example Dev Blog"
  }
}
</code></pre>
<p>The keys that start with <code>@</code> are JSON-LD keywords. The rest are Schema.org properties:</p>
<ul>
<li><p><code>@context</code> says which vocabulary the names come from. For Schema.org, it's <code>https://schema.org</code>.</p>
</li>
<li><p><code>@type</code> says what kind of thing this is. <code>BlogPosting</code> is a more specific kind of Schema.org <code>Article</code>.</p>
</li>
<li><p><code>headline</code>, <code>datePublished</code> and <code>author</code> are properties of that type. A property can hold text, a date, a URL, or another typed object, like the <code>Person</code> in <code>author</code>.</p>
</li>
<li><p><code>@id</code> gives a thing a unique name, usually a URL with a <code>#</code> fragment. Here, it marks the publisher as the same organization that another block, on the home page, describes with the same <code>@id</code>.</p>
</li>
</ul>
<p>You'll use all four in the code that follows.</p>
<h3 id="heading-structured-data-json-ld-schemaorg-and-rich-results">Structured Data, JSON-LD, Schema.org, and Rich Results</h3>
<p>These four terms get mixed up a lot, so here's how they relate:</p>
<table>
<thead>
<tr>
<th>Term</th>
<th>What it is</th>
</tr>
</thead>
<tbody><tr>
<td>Structured data</td>
<td>The idea: a machine-readable description of a page</td>
</tr>
<tr>
<td>Schema.org</td>
<td>The vocabulary: the types and properties you can use</td>
</tr>
<tr>
<td>JSON-LD</td>
<td>The format: how you write that description into the page</td>
</tr>
<tr>
<td>Rich results</td>
<td>A Google Search feature: enhanced results, like a breadcrumb trail or a product's price and rating, that structured data can make a page eligible for</td>
</tr>
</tbody></table>
<p>In short, you write structured data in JSON-LD, using the Schema.org vocabulary, and Google may use it to show a rich result.</p>
<h3 id="heading-what-structured-data-does-for-search-and-what-it-doesnt">What Structured Data Does for Search (and What It Doesn't)</h3>
<p>Google <a href="https://developers.google.com/search/docs/appearance/structured-data/intro-structured-data">says</a> it uses structured data "to understand the content of the page," and to gather information about the people, books, and companies the markup describes. It also uses it to decide whether a page is eligible for rich results.</p>
<p>Eligible is the important word. Valid JSON-LD doesn't guarantee a rich result, for four reasons:</p>
<ol>
<li><p>Each rich result has its own required properties, listed in Google's documentation for that feature. Markup can be valid Schema.org and still miss them.</p>
</li>
<li><p>Google decides whether to show the feature. Its <a href="https://developers.google.com/search/docs/appearance/structured-data/sd-policies">structured data guidelines</a> say: "Google does not guarantee that your structured data will show up in search results, even if your page is marked up correctly."</p>
</li>
<li><p>The markup has to describe content that's visible on the page. The same guidelines say: "Don't mark up content that is not visible to readers of the page."</p>
</li>
<li><p>Some types no longer produce a rich result at all. Google stopped showing FAQ rich results on May 7, 2026, and How-to rich results in 2023.</p>
</li>
</ol>
<p>Structured data isn't a ranking boost, either. As Google's John Mueller <a href="https://bsky.app/profile/johnmu.com/post/3lmoenzsfwc2c">put it in 2025</a>: "Structured data won't make your site rank better."</p>
<p>What about AI search? Google says there's "no special schema.org structured data that you need to add" to appear in its <a href="https://developers.google.com/search/docs/appearance/ai-features">AI features</a>. Bing's <a href="https://www.bing.com/webmasters/help/webmaster-guidelines-30fba23a">webmaster guidelines</a> say structured data "may support clearer grounding but does not guarantee visibility." OpenAI, Anthropic, and Perplexity don't document using it: their crawler documentation covers crawler access, not markup.</p>
<p>There's a lot of hype around AI search right now, and some of it is justified. But my reasoning doesn't depend on any one company's promise.</p>
<p>I want my content to be as understandable as possible to every system that reads it, whether that's a search engine or an AI tool. Structured data is a clear, accurate description of a page, and that's worth having whoever reads it. Just don't treat it as a trick for getting into AI answers.</p>
<p>How common is it in practice? In the <a href="https://www.greadme.com/blog/seo/greadme-state-of-websites-report-2026">State of Websites 2026 report</a> from Greadme (the website audit tool I build), 63% of 387 audited homepages had structured data. Most of it was well formed: 91% of those sites passed validation with no errors.</p>
<p>But 16% of them still declared <code>FAQPage</code>, a type whose rich result Google had limited to government and health sites in 2023 and has since retired. Valid isn't the same as useful.</p>
<h2 id="heading-how-to-build-a-safe-jsonld-component">How to Build a Safe JsonLd Component</h2>
<p>The Next.js <a href="https://nextjs.org/docs/app/guides/json-ld">JSON-LD guide</a> recommends rendering structured data "as a <code>&lt;script&gt;</code> tag in your <code>layout.js</code> or <code>page.js</code> components." You could paste that tag into every page that needs it. A small component is better, because it keeps the escaping and the types in one place.</p>
<p>Create <code>components/JsonLd.tsx</code>:</p>
<pre><code class="language-tsx">import type { Graph, Thing, WithContext } from "schema-dts";

type JsonLdData = WithContext&lt;Thing&gt; | Graph;

export function serializeJsonLd(data: JsonLdData): string {
  return JSON.stringify(data).replace(/&lt;/g, "\\u003c");
}

export function JsonLd({ data }: { data: JsonLdData }) {
  return (
    &lt;script
      type="application/ld+json"
      dangerouslySetInnerHTML={{ __html: serializeJsonLd(data) }}
    /&gt;
  );
}
</code></pre>
<p>Here's what each part does:</p>
<ul>
<li><p><code>JsonLdData</code> comes from <code>schema-dts</code>. <code>WithContext&lt;Thing&gt;</code> accepts any single Schema.org type with its <code>@context</code>, and <code>Graph</code> accepts a block that holds several. You'll use both.</p>
</li>
<li><p><code>serializeJsonLd</code> turns the object into a string and replaces every <code>&lt;</code> with <code>\u003c</code>. The sections below explain why.</p>
</li>
<li><p><code>dangerouslySetInnerHTML</code> writes that string into the tag exactly as it is. The name sounds alarming, but you control the string, and the escape is what makes it safe to include data from anywhere.</p>
</li>
</ul>
<p>The component has no <code>"use client"</code> directive, so it's a Server Component, and the tag is part of the HTML the server sends.</p>
<h3 id="heading-why-not-nextscript">Why Not next/script</h3>
<p>Next.js has a <code>Script</code> component, and some tutorials use it for JSON-LD. Don't. The JSON-LD guide explains that <code>next/script</code> "is optimized for loading and executing JavaScript," while JSON-LD is data.</p>
<p>The bigger problem shows up in the HTML. With the default <code>afterInteractive</code> strategy, <code>Script</code> content is <a href="https://nextjs.org/docs/app/api-reference/components/script#afterinteractive">"injected into the HTML client-side"</a>. I built a page that renders a <code>Product</code> block through <code>Script</code> and checked the HTML that <code>next build</code> produced.</p>
<p>There was no <code>application/ld+json</code> tag in it. The data existed only inside the JavaScript payload that React reads in the browser.</p>
<p>Google can still find it, because it <a href="https://developers.google.com/search/docs/appearance/structured-data/intro-structured-data">reads JSON-LD</a> that JavaScript injects into the page. But any tool that reads only the HTML sees nothing. A plain <code>&lt;script&gt;</code> puts the data in the HTML for everyone.</p>
<h3 id="heading-why-the-escape-matters">Why the Escape Matters</h3>
<p>Here's the short version: <code>JSON.stringify</code> gives you valid JSON, but not JSON that's safe to put inside HTML. The browser doesn't know your script contains JSON. It looks for the text <code>&lt;/script&gt;</code> to find where the tag ends, and it stops there, even in the middle of a JSON string.</p>
<p>Say a product name comes from a CMS, and someone saves this as the name:</p>
<pre><code class="language-text">Blue Mug &lt;/script&gt;&lt;script&gt;alert(document.cookie)&lt;/script&gt;
</code></pre>
<p>With plain <code>JSON.stringify</code>, the server sends this:</p>
<pre><code class="language-html">&lt;script type="application/ld+json"&gt;{"@context":"https://schema.org","@type":"Product","name":"Blue Mug &lt;/script&gt;&lt;script&gt;alert(document.cookie)&lt;/script&gt;"}&lt;/script&gt;
</code></pre>
<p>The browser ends the JSON-LD tag at the first <code>&lt;/script&gt;</code>. Then it finds a second, ordinary script tag and runs it. That's a cross-site scripting (XSS) attack, and your structured data is now broken JSON as well.</p>
<p>I ran that page through jsdom, which parses HTML the way the HTML standard specifies. The <code>alert</code> ran once, and <code>JSON.parse</code> on the JSON-LD failed with "Unterminated string in JSON."</p>
<p>With the escape, the same value becomes:</p>
<pre><code class="language-html">&lt;script type="application/ld+json"&gt;{"@context":"https://schema.org","@type":"Product","name":"Blue Mug \u003c/script&gt;\u003cscript&gt;alert(document.cookie)\u003c/script&gt;"}&lt;/script&gt;
</code></pre>
<p>There's no <code>&lt;/script&gt;</code> left for the browser to find. <code>\u003c</code> is JSON's own escape for <code>&lt;</code>, so any JSON parser reads it back as the original character. In the same test, nothing ran, and <code>JSON.parse</code> returned the exact name the CMS stored.</p>
<p>You don't need an attacker for this to break a page. The <a href="https://html.spec.whatwg.org/multipage/scripting.html#restrictions-for-contents-of-script-elements">HTML standard</a> also lists <code>&lt;!--</code> and <code>&lt;script</code> as sequences that confuse the parser inside a script tag.</p>
<p>In my test, a value containing <code>&lt;!--&lt;script&gt;</code> made the unescaped tag swallow the rest of the page, and the heading after it disappeared from the DOM. With the escape, the page rendered normally.</p>
<p>That's why the Next.js guide recommends replacing <code>&lt;</code> with <code>\u003c</code>. The guide itself only added that advice <a href="https://github.com/vercel/next.js/pull/79627">in May 2025</a>, and many tutorials still use plain <code>JSON.stringify</code>. If your JSON-LD includes anything you didn't type yourself, like titles, descriptions, product names, or reviews, escape it.</p>
<h3 id="heading-why-one-component">Why One Component</h3>
<p>I usually build a component when I notice several places doing the same thing. I want one central place that owns that behavior, so a change or a fix happens once instead of in every copy.</p>
<p>JSON-LD is a good example, because the escape is one line and easy to forget. In a production codebase I maintain, structured data was rendered in nine places.</p>
<p>Seven of them escaped <code>&lt;</code>. Two didn't, and one of those was the component that rendered the structured data for every blog article.</p>
<p>Nothing broke. The article descriptions it handled contain tags like <code>&lt;body&gt;</code> and <code>&lt;video&gt;</code>, which can't end a script tag, and none of them contained <code>&lt;/script</code> or <code>&lt;!--</code>.</p>
<p>But that was luck, not a decision. Whether a page was protected depended on which file you opened.</p>
<p>Moving every block into one <code>JsonLd</code> component fixed that for good. The escape, the choice of a plain <code>&lt;script&gt;</code> over <code>next/script</code>, and the types now live in one place. Every call site gets type checking from the prop type, and <code>serializeJsonLd</code> can be tested on its own.</p>
<h2 id="heading-how-to-add-organization-and-website-data-to-the-home-page">How to Add Organization and WebSite Data to the Home Page</h2>
<p>Start with the data that describes your site as a whole: the organization behind it and the website itself. Google <a href="https://developers.google.com/search/docs/appearance/structured-data/organization">recommends</a> placing organization data "on your home page, or a single page that describes your organization," and adds: "You don't need to include it on every page of your site."</p>
<p>The examples below use two constants for the site's name and address. Put them wherever you keep your configuration:</p>
<pre><code class="language-ts">// lib/site.ts
export const SITE_URL = "https://example.com";
export const SITE_NAME = "Example Dev Blog";
</code></pre>
<p>Then render both types from the home page, <code>app/page.tsx</code>:</p>
<pre><code class="language-tsx">import type { Graph } from "schema-dts";
import { JsonLd } from "@/components/JsonLd";
import { SITE_NAME, SITE_URL } from "@/lib/site";

const siteJsonLd: Graph = {
  "@context": "https://schema.org",
  "@graph": [
    {
      "@type": "Organization",
      "@id": `${SITE_URL}/#organization`,
      name: SITE_NAME,
      url: SITE_URL,
      logo: `${SITE_URL}/logo.png`,
    },
    {
      "@type": "WebSite",
      "@id": `${SITE_URL}/#website`,
      name: SITE_NAME,
      url: SITE_URL,
      publisher: { "@id": `${SITE_URL}/#organization` },
    },
  ],
};

export default function HomePage() {
  return (
    &lt;main&gt;
      &lt;JsonLd data={siteJsonLd} /&gt;
      &lt;h1&gt;{SITE_NAME}&lt;/h1&gt;
      {/* The rest of your home page */}
    &lt;/main&gt;
  );
}
</code></pre>
<p><code>@graph</code> holds several things in one block that share a single <code>@context</code>. That's why this object is typed as <code>Graph</code> instead of <code>WithContext&lt;...&gt;</code>.</p>
<p>Each item has an <code>@id</code>, and the <code>WebSite</code>'s <code>publisher</code> refers to the <code>Organization</code> by that <code>@id</code> instead of repeating it. Inside one block, a reference with only an <code>@id</code> is enough, because the full definition is right next to it.</p>
<p>You might be tempted to put this in the root layout instead, so it appears everywhere. In the App Router, anything you render in a layout is part of every page under it.</p>
<p>That isn't wrong, but it adds the same block to every page, which Google says you don't need. Use a layout for structured data only when the data really describes every page below it.</p>
<h2 id="heading-how-to-add-article-and-breadcrumb-data-to-a-dynamic-route">How to Add Article and Breadcrumb Data to a Dynamic Route</h2>
<p>Article pages are where structured data earns its keep, and where it most often goes stale. The rule that prevents both problems: build the JSON-LD from the same data the page renders, and mark up only what the reader can see.</p>
<p>Here's a complete <code>app/blog/[slug]/page.tsx</code>:</p>
<pre><code class="language-tsx">import Image from "next/image";
import Link from "next/link";
import { notFound } from "next/navigation";
import type { BlogPosting, BreadcrumbList, WithContext } from "schema-dts";
import { JsonLd } from "@/components/JsonLd";
import { getAllPosts, getPost } from "@/lib/posts";
import { SITE_NAME, SITE_URL } from "@/lib/site";

export async function generateStaticParams() {
  const posts = await getAllPosts();
  return posts.map((post) =&gt; ({ slug: post.slug }));
}

export default async function PostPage({
  params,
}: {
  params: Promise&lt;{ slug: string }&gt;;
}) {
  const { slug } = await params;
  const post = await getPost(slug);
  if (!post) notFound();

  const breadcrumbs = [
    { name: "Home", path: "/" },
    { name: "Blog", path: "/blog" },
    { name: post.title, path: `/blog/${post.slug}` },
  ];

  const articleJsonLd: WithContext&lt;BlogPosting&gt; = {
    "@context": "https://schema.org",
    "@type": "BlogPosting",
    headline: post.title,
    description: post.description,
    image: post.image,
    datePublished: post.publishedAt,
    dateModified: post.updatedAt,
    author: { "@type": "Person", name: post.author.name, url: post.author.url },
    publisher: {
      "@type": "Organization",
      "@id": `${SITE_URL}/#organization`,
      name: SITE_NAME,
    },
  };

  const breadcrumbJsonLd: WithContext&lt;BreadcrumbList&gt; = {
    "@context": "https://schema.org",
    "@type": "BreadcrumbList",
    itemListElement: breadcrumbs.map((crumb, index) =&gt; ({
      "@type": "ListItem",
      position: index + 1,
      name: crumb.name,
      item: new URL(crumb.path, SITE_URL).href,
    })),
  };

  return (
    &lt;article&gt;
      &lt;JsonLd data={articleJsonLd} /&gt;
      &lt;JsonLd data={breadcrumbJsonLd} /&gt;

      &lt;nav aria-label="Breadcrumb"&gt;
        {breadcrumbs.map((crumb, index) =&gt; (
          &lt;span key={crumb.path}&gt;
            {index &gt; 0 &amp;&amp; " / "}
            &lt;Link href={crumb.path}&gt;{crumb.name}&lt;/Link&gt;
          &lt;/span&gt;
        ))}
      &lt;/nav&gt;

      &lt;h1&gt;{post.title}&lt;/h1&gt;
      &lt;p&gt;
        By &lt;a href={post.author.url}&gt;{post.author.name}&lt;/a&gt; ·{" "}
        &lt;time dateTime={post.publishedAt}&gt;{post.publishedAt.slice(0, 10)}&lt;/time&gt;
      &lt;/p&gt;
      &lt;Image src={post.image} alt="" width={1200} height={675} /&gt;
      &lt;p&gt;{post.description}&lt;/p&gt;
    &lt;/article&gt;
  );
}
</code></pre>
<p><code>next/image</code> only loads remote images from hosts you allow, so add your image host to <a href="https://nextjs.org/docs/app/api-reference/components/image#remotepatterns"><code>images.remotePatterns</code></a> in <code>next.config.ts</code> if it isn't there already.</p>
<p>Every value in <code>articleJsonLd</code> comes from <code>post</code>, the same object the JSX renders. The headline is the <code>&lt;h1&gt;</code>, the author is the byline, and the dates are the date on the page.</p>
<p>If an editor changes the title, both change together. Compare that with a hardcoded <code>dateModified</code> or a copied-in rating, which stay the same while the page moves on.</p>
<p>The breadcrumbs work the same way. One <code>breadcrumbs</code> array produces both the visible navigation and the <code>BreadcrumbList</code>, so the markup can't describe a trail the reader doesn't see. Google <a href="https://developers.google.com/search/docs/appearance/structured-data/breadcrumb">requires</a> a <code>position</code> and a <code>name</code> for each item, an <code>item</code> URL for every item except the last, and at least two items.</p>
<p>Two things matter most to me with structured data. First, it has to be implemented correctly, which is what the validation sections below are for.</p>
<p>Second, it has to match what the reader can actually see. If a piece of information exists only in the JSON-LD and not on the page, it shouldn't be there.</p>
<p>Google's own <a href="https://developers.google.com/search/docs/appearance/structured-data/sd-policies">guidelines</a> say the same, and Bing's say misleading markup "may be ignored." Building the JSON-LD from the rendered data is the simplest way to follow that rule without thinking about it.</p>
<p>The <code>publisher</code> includes a <code>name</code> next to its <code>@id</code>. On the home page, a bare <code>@id</code> was enough, because the full <code>Organization</code> sat in the same block.</p>
<p>Here, it's on a different page, and tools that check one page at a time can't see it. The name keeps this page's data complete on its own, and the shared <code>@id</code> still marks it as the same organization.</p>
<p>Article has no required properties in Google's <a href="https://developers.google.com/search/docs/appearance/structured-data/article">Article documentation</a>. It recommends <code>author</code>, <code>datePublished</code>, <code>dateModified</code>, <code>headline</code> and <code>image</code>, with dates in ISO 8601 format and a time zone. The example above includes all of them.</p>
<p>The <code>schema-dts</code> types catch mistakes while you type. If you misspell a property, TypeScript stops you:</p>
<pre><code class="language-text">Object literal may only specify known properties, but 'headLine' does not exist in type
'BlogPostingLeaf &amp; { "@context": "https://schema.org"; }'. Did you mean to write 'headline'?
</code></pre>
<p>They also catch the wrong <code>@type</code> for the annotation and the wrong kind of value, like a number for <code>datePublished</code>.</p>
<p>What they can't catch is anything that depends on Google's rules or on what's actually on the page. A date string like <code>"last Tuesday"</code> type-checks fine. That's what validation is for.</p>
<h2 id="heading-how-to-validate-your-structured-data">How to Validate Your Structured Data</h2>
<p>Validation happens in two places: the HTML your server actually sends, and the tools that read it the way a search engine does.</p>
<h3 id="heading-check-what-actually-lands-in-the-html">Check What Actually Lands in the HTML</h3>
<p>Start by looking at the real output, not your source code. Build and start the app:</p>
<pre><code class="language-bash">npm run build
npm start
</code></pre>
<p>Then, in another terminal, fetch a page and pull out its JSON-LD:</p>
<pre><code class="language-bash">curl -s http://localhost:3000/blog/nextjs-caching \
  | grep -o '&lt;script type="application/ld+json"&gt;[^&lt;]*&lt;/script&gt;'
</code></pre>
<p>You should see one line per block:</p>
<pre><code class="language-html">&lt;script type="application/ld+json"&gt;{"@context":"https://schema.org","@type":"BlogPosting","headline":"How Caching Works in Next.js","description":"A practical tour of the \u003cLink&gt; prefetch, the data cache and revalidation.","image":"https://example.com/images/nextjs-caching.png","datePublished":"2026-09-01T09:00:00.000Z","dateModified":"2026-09-20T12:00:00.000Z","author":{"@type":"Person","name":"Jane Doe","url":"https://example.com/authors/jane-doe"},"publisher":{"@type":"Organization","@id":"https://example.com/#organization","name":"Example Dev Blog"}}&lt;/script&gt;
&lt;script type="application/ld+json"&gt;{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://example.com/"},{"@type":"ListItem","position":2,"name":"Blog","item":"https://example.com/blog"},{"@type":"ListItem","position":3,"name":"How Caching Works in Next.js","item":"https://example.com/blog/nextjs-caching"}]}&lt;/script&gt;
</code></pre>
<p>The description shows the escape at work. The post's description mentions the <code>&lt;Link&gt;</code> component, and its <code>&lt;</code> arrives as <code>\u003c</code>.</p>
<p>This check also catches the <code>next/script</code> problem from earlier and any JSON-LD added in a <code>useEffect</code>. If the data is only added in the browser, the <code>grep</code> finds nothing. You can do the same check with your browser's View Source, but not with the developer tools' Elements panel, which shows the page after JavaScript has run.</p>
<p>You might also notice that <code>application/ld+json</code> appears more often in the full response than there are tags. Next.js sends the rendered React tree a second time as the React Server Components payload, the data React uses to hydrate the page, and your JSON-LD string is part of that tree.</p>
<p>So every byte of structured data ships twice. That's a good reason to keep JSON-LD to the properties you need, and not to copy a whole article body into it.</p>
<h3 id="heading-use-the-online-validators">Use the Online Validators</h3>
<p>Two free tools check structured data from a search engine's point of view, and each answers a different question.</p>
<p>The <a href="https://search.google.com/test/rich-results">Rich Results Test</a> is Google's tool. It <a href="https://support.google.com/webmasters/answer/7445569">shows</a> which Google rich result types it found on a page, along with any errors or suggestions.</p>
<p>It works best with a URL. A preview deployment works well for that, and Google <a href="https://developers.google.com/search/docs/appearance/structured-data/generate-structured-data-with-javascript">recommends</a> the URL input over the code input "because there are JavaScript limitations when using the code input." For a local build, paste the HTML from <code>curl</code> into its code tab.</p>
<img src="https://cdn.hashnode.com/uploads/covers/66c44f7dd6285e754adb356c/ca103ea7-13f7-4c4a-be8a-11a1e0a08de2.png" alt="Google's Rich Results Test showing 2 valid items detected for the example blog post: Articles and Breadcrumbs, with 1 valid item each" style="display: block;" width="1298" height="832" loading="lazy">

<p>The <a href="https://validator.schema.org/">Schema Markup Validator</a> checks your markup against the Schema.org vocabulary itself. Google's <a href="https://developers.google.com/search/blog/2020/12/structured-data-testing-tool-update">announcement</a> of the tool describes its purpose as checking "syntax and compliance of markup with schema.org standards," without checking Google's rich result types. Use it for types Google doesn't use for rich results, or when you want to know that the markup is valid Schema.org regardless of any search engine.</p>
<img src="https://cdn.hashnode.com/uploads/covers/66c44f7dd6285e754adb356c/a5bcea2b-f6be-4656-b52a-b844a769a683.png" alt="The Schema Markup Validator showing 0 errors and 0 warnings for the example blog post, with BreadcrumbList and BlogPosting detected" style="display: block;" width="1280" height="860" loading="lazy">

<p>After you deploy, Google Search Console takes over. Its rich result reports show valid items and errors across every page Google has crawled, and the URL Inspection tool shows what Google saw on a single page. Google's <a href="https://developers.google.com/search/docs/appearance/structured-data/intro-structured-data">own advice</a> is to use the Rich Results Test "during development, and the Rich result status reports after deployment."</p>
<h2 id="heading-how-to-validate-json-ld-automatically-after-every-build">How to Validate JSON-LD Automatically After Every Build</h2>
<p>Structured data has a lot of types, properties and rules, and it's easy to make a mistake in the syntax or the implementation. You already deal with that kind of risk everywhere else in software development: you check types, run linters, and write tests, so problems show up before users see them. Structured data shouldn't be any different.</p>
<p>The online tools are great for a first check, but nobody pastes every URL into them after every change. Structured data usually breaks later, quietly: someone renames a field in the CMS, a refactor drops a property, or a heading changes and the JSON-LD doesn't. A small script that runs after every build catches those regressions before they ship.</p>
<p>This one fetches your pages from the running app and checks four things:</p>
<ol>
<li><p>Every JSON-LD block is valid JSON.</p>
</li>
<li><p><code>@context</code> is <code>https://schema.org</code>.</p>
</li>
<li><p>Each type has the properties your site promises, including Google's required breadcrumb fields.</p>
</li>
<li><p>The <code>BlogPosting</code> headline matches the page's <code>&lt;h1&gt;</code>, the visible-content rule as a check.</p>
</li>
</ol>
<p>Create <code>scripts/check-jsonld.mjs</code>:</p>
<pre><code class="language-js">// Checks the JSON-LD on a running Next.js server: npm run build &amp;&amp; npm start, then run this.
const BASE_URL = process.env.BASE_URL ?? "http://localhost:3000";

// Pages that should carry structured data.
const PAGES = ["/", "/blog/nextjs-caching"];

// The properties this site promises for each type.
const REQUIRED = {
  Organization: ["name", "url", "logo"],
  WebSite: ["name", "url"],
  BlogPosting: ["headline", "datePublished", "author", "image"],
  BreadcrumbList: ["itemListElement"],
};

const errors = [];

function fail(page, message) {
  errors.push(page + ": " + message);
}

function decodeEntities(text) {
  return text
    .replace(/&amp;lt;/g, "&lt;")
    .replace(/&amp;gt;/g, "&gt;")
    .replace(/&amp;quot;/g, '"')
    .replace(/&amp;#x27;|&amp;#39;/g, "'")
    .replace(/&amp;amp;/g, "&amp;");
}

function checkBreadcrumbs(node, page) {
  const items = node.itemListElement ?? [];
  if (items.length &lt; 2) {
    fail(page, "BreadcrumbList needs at least two items");
  }
  items.forEach((item, index) =&gt; {
    const isLast = index === items.length - 1;
    if (item.position !== index + 1 || !item.name || (!isLast &amp;&amp; !item.item)) {
      fail(page, `breadcrumb ${index + 1} needs position, name and item`);
    }
  });
}

for (const page of PAGES) {
  const html = await (await fetch(BASE_URL + page)).text();

  // Safe to match with a regex because the JsonLd component escapes every "&lt;".
  const blocks = [
    ...html.matchAll(/&lt;script type="application\/ld\+json"&gt;(.*?)&lt;\/script&gt;/gs),
  ].map((match) =&gt; match[1]);

  if (blocks.length === 0) {
    fail(page, "no JSON-LD found");
    continue;
  }

  const h1 = html.match(/&lt;h1[^&gt;]*&gt;(.*?)&lt;\/h1&gt;/s)?.[1].replace(/&lt;[^&gt;]+&gt;/g, "");

  for (const block of blocks) {
    let data;
    try {
      data = JSON.parse(block);
    } catch (error) {
      fail(page, `invalid JSON (${error.message})`);
      continue;
    }

    if (data["@context"] !== "https://schema.org") {
      fail(page, '@context should be "https://schema.org"');
    }

    for (const node of data["@graph"] ?? [data]) {
      const type = node["@type"];
      for (const property of REQUIRED[type] ?? []) {
        if (node[property] === undefined) {
          fail(page, type + ' is missing "' + property + '"');
        }
      }
      if (type === "BreadcrumbList") checkBreadcrumbs(node, page);
      if (
        type === "BlogPosting" &amp;&amp;
        node.headline !== decodeEntities(h1 ?? "")
      ) {
        fail(page, `headline "${node.headline}" doesn't match the &lt;h1&gt;`);
      }
    }
  }
}

if (errors.length &gt; 0) {
  console.error(errors.join("\n"));
  process.exit(1);
}
console.log(`JSON-LD OK on ${PAGES.length} pages`);
</code></pre>
<p>A few details are worth pointing out:</p>
<ul>
<li><p><code>REQUIRED</code> is your own contract, not Google's. Google lists no required properties for Article, so the list says what this site promises to include. Add a type to it when you start using one.</p>
</li>
<li><p>The regex that finds the blocks is reliable here only because the <code>JsonLd</code> component escapes every <code>&lt;</code>. No value can contain <code>&lt;/script&gt;</code>, so the first <code>&lt;/script&gt;</code> always ends the block. The escape protects your tests as well as your users.</p>
</li>
<li><p>React escapes characters like <code>'</code> and <code>&amp;</code> in the <code>&lt;h1&gt;</code>, so <code>decodeEntities</code> turns them back before the headline comparison.</p>
</li>
</ul>
<p>The script uses the built-in <code>fetch</code>, so it needs no dependencies. Add it to <code>package.json</code>:</p>
<pre><code class="language-json">{
  "scripts": {
    "check:jsonld": "node scripts/check-jsonld.mjs"
  }
}
</code></pre>
<p>With <code>npm start</code> running, run it in a second terminal:</p>
<pre><code class="language-bash">npm run check:jsonld
</code></pre>
<p>When everything is in order, it prints <code>JSON-LD OK on 2 pages</code>. To see it fail, I removed the organization's <code>logo</code>, changed the post's <code>&lt;h1&gt;</code> without changing its data, and added the unescaped page from earlier to the list. The script reported all three and exited with code 1:</p>
<pre><code class="language-text">/: Organization is missing "logo"
/blog/nextjs-caching: headline "How Caching Works in Next.js" doesn't match the &lt;h1&gt;
/experiments/unescaped: invalid JSON (Unterminated string in JSON at position 68 (line 1 column 69))
</code></pre>
<p>In CI, run it after <code>npm run build</code>, with <code>npm start</code> running in the background, and set <code>BASE_URL</code> if the server isn't on port 3000. The non-zero exit code fails the job, so broken structured data never reaches production.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Structured data describes your pages to search engines in a form they don't have to guess at. In this tutorial, you added it to a Next.js App Router site:</p>
<ul>
<li><p>A <code>JsonLd</code> component that renders a plain <code>&lt;script&gt;</code> and escapes <code>&lt;</code>, so no value can break out of the tag</p>
</li>
<li><p>Organization and website data on the home page, linked with <code>@id</code></p>
</li>
<li><p>Article and breadcrumb data built from the same data the page renders</p>
</li>
<li><p>Checks for what lands in the HTML, the online validators, and a script that validates your JSON-LD after every build</p>
</li>
</ul>
<p>I'd call structured data almost essential today. It's also never been easier to write: an AI assistant can generate a JSON-LD block for any page in seconds. But generated isn't the same as correct.</p>
<p>Check that what it wrote is valid, that it includes the properties Google asks for, and that every value matches what's actually on your page. That's what the validators and the check script are for.</p>
<p>And remember that valid markup makes a page eligible for rich results, not guaranteed to get them.</p>
<p>If you want a second opinion on a live page, the free <a href="https://www.greadme.com/schema-validator">Greadme Schema Validator</a> checks any URL against Schema.org and Google's rich result requirements, with no sign-up needed.</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
