Performance: Request memoization
MEDIUM IMPACT
Request memoization improves page load speed by avoiding repeated data fetching and reduces server load and client wait times.
export async function getServerSideProps(context) { const res = await fetch('https://api.example.com/data'); const data = await res.json(); return { props: { data1: data, data2: data } }; }
export async function getServerSideProps(context) { const res1 = await fetch('https://api.example.com/data'); const data1 = await res1.json(); const res2 = await fetch('https://api.example.com/data'); const data2 = await res2.json(); return { props: { data1, data2 } }; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Duplicate fetch calls | Multiple fetch triggers | Multiple reflows due to delayed data | Higher paint cost from repeated updates | [X] Bad |
| Single fetch with memoization | Single fetch triggers | Single reflow after data arrives | Lower paint cost with stable data | [OK] Good |