Performance: Structured data (JSON-LD)
Structured data affects page load speed slightly by adding script tags but mainly impacts SEO and rich results, not visual rendering.
import Head from 'next/head' export default function Page() { const jsonLd = { "@context": "https://schema.org", "@type": "Organization", "name": "Example" }; return ( <> <Head> <script type="application/ld+json" dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }} key="jsonld" /> </Head> <h1>Welcome</h1> </> ) }
export default function Page() { return ( <> <script type="application/ld+json"> {`{ "@context": "https://schema.org", "@type": "Organization", "name": "Example" }`} </script> <h1>Welcome</h1> </> ) }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Embedding JSON-LD as React children | Multiple text nodes created | 0 | Minimal but increased parsing time | [X] Bad |
| Injecting JSON-LD via Next.js Head with dangerouslySetInnerHTML | Single script node | 0 | Minimal parsing cost | [OK] Good |
Script component from next/script to safely add scripts including JSON-LD.dangerouslySetInnerHTML to avoid React escaping it.import Script from 'next/script';
const data = {"@context": "https://schema.org", "@type": "Person", "name": "Alice"};
export default function Page() {
return (
<>
<h1>Profile</h1>
<Script type="application/ld+json" dangerouslySetInnerHTML={{ __html: JSON.stringify(data) }} />
</>
);
}Script component renders a <script> tag with the specified type and inner HTML.application/ld+json.import Script from 'next/script';
const data = {"@context": "https://schema.org", "@type": "Organization", "name": "My Company"};
export default function Home() {
return (
<Script type="application/ld+json">{JSON.stringify(data)}</Script>
);
}Script component requires dangerouslySetInnerHTML to insert raw JSON-LD content inside the script tag.Script components each with their own JSON-LD data using dangerouslySetInnerHTML.Pass the test and this pattern moves unknown