Description
The frontend has no performance optimization strategy. Page load times, bundle sizes, image optimization, and runtime performance are all unaddressed. For a data-heavy dashboard with real-time updates, performance is critical to user experience.
Performance gaps:
- No bundle analysis or size budget
- No image optimization (next/image not used)
- No code splitting or lazy loading
- No memoization of expensive components
- No virtualization for long lists (react-window or tanstack-virtual)
- No font optimization (Geist fonts loaded without display=swap or preload)
- No CSS optimization (unused Tailwind classes not purged)
- No runtime performance monitoring (Core Web Vitals)
- No stale-while-revalidate caching strategy for API data
- No compression middleware consideration
Technical Context & Impact
- Affected Components/Files:
app/layout.tsx, app/page.tsx, next.config.ts
- Impact: Slow page loads, poor Core Web Vitals, high bounce rate
Step-by-Step Implementation Guide
- Install and configure bundle analyzer:
npm install @next/bundle-analyzer; add to next.config.ts
- Analyze current bundle: Run
ANALYZE=true npm run build to identify large dependencies
- Implement code splitting: Use
next/dynamic for:
- Chart components (heavy libraries)
- Admin panel (only admins use it)
- Data tables (virtualized for large datasets)
- Optimize fonts in layout.tsx: Add
display="swap" and preload={true} to Geist font config
- Implement virtualization:
src/components/virtual/:
VirtualizedMeterList.tsx using @tanstack/react-virtual for 1000+ meters
VirtualizedStreamTable.tsx for large stream lists
- Add memoization:
React.memo on chart components, card lists, and table rows; useMemo for computed data
- Optimize images: Use
next/image for any static assets in public/; add width/height to prevent Cumulative Layout Shift
- Add Web Vitals monitoring:
src/lib/monitoring/web-vitals.ts reporting to analytics
- Configure caching headers: In
next.config.ts add Cache-Control headers for static assets
- Implement route prefetching:
Link components with prefetch={true} for dashboard sub-pages
- Set performance budgets: In CI, enforce bundle size < 500KB (gzipped) and Lighthouse Performance score > 90
Verification & Testing Steps
- Run
npm run build with bundle analyzer and identify largest chunks
- Measure Lighthouse Performance score before and after optimization
- Render 1000 meters in virtualized list and measure scroll performance (should be 60fps)
- Test page load with Slow 3G throttling in DevTools
- Verify Core Web Vitals: LCP < 2.5s, FID < 100ms, CLS < 0.1
- Run
npx tsc --noEmit
Description
The frontend has no performance optimization strategy. Page load times, bundle sizes, image optimization, and runtime performance are all unaddressed. For a data-heavy dashboard with real-time updates, performance is critical to user experience.
Performance gaps:
Technical Context & Impact
app/layout.tsx,app/page.tsx,next.config.tsStep-by-Step Implementation Guide
npm install @next/bundle-analyzer; add tonext.config.tsANALYZE=true npm run buildto identify large dependenciesnext/dynamicfor:display="swap"andpreload={true}to Geist font configsrc/components/virtual/:VirtualizedMeterList.tsxusing@tanstack/react-virtualfor 1000+ metersVirtualizedStreamTable.tsxfor large stream listsReact.memoon chart components, card lists, and table rows;useMemofor computed datanext/imagefor any static assets inpublic/; add width/height to prevent Cumulative Layout Shiftsrc/lib/monitoring/web-vitals.tsreporting to analyticsnext.config.tsaddCache-Controlheaders for static assetsLinkcomponents withprefetch={true}for dashboard sub-pagesVerification & Testing Steps
npm run buildwith bundle analyzer and identify largest chunksnpx tsc --noEmit