Performance: Why SEO matters for Next.js
SEO impacts how fast and well search engines can index your Next.js pages, affecting your site's visibility and user traffic.
export async function getServerSideProps() { const res = await fetch('https://api.example.com/data'); const data = await res.json(); return { props: { text: data.text } }; } export default function Page({ text }) { return <div>{text}</div>; }
export default function Page() { return <div>{fetch('/api/data').then(res => res.json()).then(data => data.text)}</div>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Client-side data fetching | Minimal initially, but delayed DOM update | Multiple reflows as content loads | Higher paint cost due to incremental updates | [X] Bad |
| Server-side rendering with getServerSideProps | Full DOM ready on load | Single reflow | Lower paint cost with immediate content | [OK] Good |
<Head> component to insert metadata like titles and descriptions.<Head>, not <Meta>, <Title>, or <SEO>.import Head from 'next/head';
export default function Home() {
return (
<>
My Next.js Site
Content here
</>
);
}<Head> componentHead and uses it to add a <title> and <meta name="description"> tag.import Head from 'next/head';
export default function About() {
return (
<>
About Us
About content
</>
);
}name="description", not just description="...".<title> is correctly inside <Head>, and <main> inside fragments is valid.<Head> tags for each post, improving SEO.Pass the test and this pattern moves unknown