Performance: Why caching matters
HIGH IMPACT
Caching improves page load speed and reduces server response time by storing data closer to the user or in memory.
const cache = new Map(); app.get('/data', async (req, res) => { if (cache.has('data')) { return res.json(cache.get('data')); } const data = await fetchFromDatabase(); cache.set('data', data); res.json(data); });
app.get('/data', async (req, res) => { const data = await fetchFromDatabase(); res.json(data); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No caching, fetch on every request | N/A | N/A | High due to slow data arrival | [X] Bad |
| In-memory caching for repeated data | N/A | N/A | Low, data served instantly | [OK] Good |