Rendering strategy decides how and when your web page shows content to users. It affects speed, user experience, and how search engines see your site.
Why rendering strategy matters in NextJS
export const dynamic = 'force-static'; export default function Page() { return <h1>Hello, world!</h1>; }
Next.js uses different rendering strategies like Static Generation and Server-side Rendering.
You can control rendering by exporting special variables or using functions like getStaticProps or getServerSideProps.
export const dynamic = 'force-static'; export default function Page() { return <h1>Static Page</h1>; }
export const dynamic = 'force-dynamic'; export default function Page() { return <h1>Dynamic Page</h1>; }
export async function getStaticProps() { return { props: { time: new Date().toISOString() } }; } export default function Page({ time }) { return <p>Build time: {time}</p>; }
export async function getServerSideProps() { return { props: { time: new Date().toISOString() } }; } export default function Page({ time }) { return <p>Request time: {time}</p>; }
This example shows a page that fetches the current time from an API on the client side. The page loads quickly with a placeholder, then updates with fresh data.
This approach uses client-side rendering to keep content fresh without reloading the whole page.
import { useState, useEffect } from 'react'; export default function TimePage() { const [time, setTime] = useState('Loading...'); useEffect(() => { fetch('/api/time') .then(res => res.json()) .then(data => setTime(data.time)); }, []); return <main> <h1>Current Time</h1> <p>{time}</p> </main>; } // API route (pages/api/time.js) export default function handler(req, res) { res.status(200).json({ time: new Date().toISOString() }); }
Choosing the right rendering strategy helps your site load faster and feel smoother.
Static pages are great for content that doesn't change often.
Dynamic rendering is better for personalized or frequently updated content.
Rendering strategy controls when and how your page content is created and shown.
It affects speed, freshness, and SEO of your website.
Next.js gives you tools to pick the best strategy for each page.