Performance: Progressive enhancement
Progressive enhancement improves initial page load speed and interaction responsiveness by delivering a basic functional experience first, then layering advanced features.
export default function Page() {
return (
<main>
<h1>Basic content visible immediately</h1>
<noscript>Please enable JavaScript for enhanced features.</noscript>
</main>
);
}
// Then progressively enhance with client-side JS for interactivityimport { useEffect } from 'react'; export default function Page() { useEffect(() => { // heavy JS feature initialization initializeComplexUI(); }, []); return <div>{/* complex UI only rendered after JS loads */}</div>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy JS blocking initial render | Minimal initially, then large | Multiple reflows as JS modifies DOM | High paint cost after JS loads | [X] Bad |
| Server-rendered HTML with deferred JS | Full DOM ready on load | Single reflow on initial load | Low paint cost, fast first paint | [OK] Good |
export async function loader() {
return { message: 'Hello from server' };
}
export default function Greeting() {
const data = useLoaderData();
return <div>{data.message}</div>;
}export default function Page() {
React.useEffect(() => {
fetch('/api/data').then(res => res.json()).then(console.log);
}, []);
return <div>Loading...</div>;
}Pass the test and this pattern moves unknown