0
0
NextJSframework~8 mins

Static export option in NextJS - Performance & Optimization

Choose your learning style9 modes available
Performance: Static export option
HIGH IMPACT
This affects the page load speed by pre-generating HTML at build time, reducing server work and improving initial content display.
Delivering fast initial page load for mostly static content
NextJS
export async function getStaticProps() {
  const res = await fetch('https://example.com/api/data');
  const data = await res.json();
  return { props: { data } };
}

export default function Page({ data }) {
  return <div>{data.content}</div>;
}
Pre-fetching data at build time generates static HTML, so page loads instantly without client fetch.
📈 Performance GainImproves LCP by eliminating client fetch delay; content is ready on first paint.
Delivering fast initial page load for mostly static content
NextJS
export default function Page() {
  const [data, setData] = React.useState(null);
  React.useEffect(() => {
    fetch('/api/data').then(res => res.json()).then(setData);
  }, []);
  if (!data) return <p>Loading...</p>;
  return <div>{data.content}</div>;
}
Fetching data on the client delays content rendering and increases time to first meaningful paint.
📉 Performance CostBlocks LCP until client fetch completes; adds network delay on every page load.
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Client-side data fetchMinimal initially, but updates DOM after fetchTriggers at least 1 reflow after data arrivesPaint delayed until data fetch completes[X] Bad
Static export with getStaticPropsFull DOM ready on loadNo reflows caused by data fetchingPaint happens immediately with full content[OK] Good
Rendering Pipeline
Static export pre-renders HTML and CSS during build, so browser receives fully formed content, skipping server rendering and client data fetching.
HTML Generation
Network Transfer
First Paint
⚠️ BottleneckNetwork Transfer and First Paint if content is fetched client-side
Core Web Vital Affected
LCP
This affects the page load speed by pre-generating HTML at build time, reducing server work and improving initial content display.
Optimization Tips
1Pre-build pages with getStaticProps to serve ready HTML and speed up LCP.
2Avoid client-side data fetching for main content to reduce delays and reflows.
3Use static export for mostly static sites to minimize server load and improve user experience.
Performance Quiz - 3 Questions
Test your performance knowledge
How does using Next.js static export affect Largest Contentful Paint (LCP)?
AIt improves LCP by serving pre-built HTML with content ready to display.
BIt worsens LCP by adding extra server processing on each request.
CIt has no effect on LCP because content is fetched client-side.
DIt delays LCP due to additional JavaScript parsing.
DevTools: Performance
How to check: Record page load and look for time to first contentful paint and network requests; check if main content appears immediately or after fetch.
What to look for: Short time to first contentful paint and absence of delayed data fetch network calls indicate good static export performance.