Performance: Why Next.js over plain React
This affects page load speed and time to interactive by optimizing server rendering and static generation.
import React from 'react'; export default function Home() { return <h1>Hello World</h1>; } // Next.js automatically pre-renders this page at build time or on server request
import React from 'react'; import ReactDOM from 'react-dom/client'; function App() { return <h1>Hello World</h1>; } const root = ReactDOM.createRoot(document.getElementById('root')); root.render(<App />);
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Plain React client-side render | High (builds DOM after JS loads) | Multiple (JS triggers layout) | High (delayed paint) | [X] Bad |
| Next.js server-side or static render | Low (HTML sent ready) | Single (initial layout) | Low (fast paint) | [OK] Good |
pages folder where each file automatically becomes a route.pages exports a page; no manual routing needed.pages folder with a React component export. -> Option Dpages folder [OK]export default function Home() {
return <h1>Welcome to Next.js!</h1>
}<h1> element with text 'Welcome to Next.js!'.export default function About() {
return (
<div>
<h2>About Page</h2>
<p>Learn more about us.</p>
</div>
)
}Pass the test and this pattern moves unknown