Performance
React javascript framework.
Long term performance across all metrics business and technical.
Subjects
Next Faster
Github NextFaster
Planning
Best Practice Workflow with React.
- Identify your component's different visual states
- Determine what triggers those state changes
- Represent the state in memory using useState
- Remove any non-essential state variables
- Connect the event handlers to set the state
- How much complexity?
- Should complexity be handled at the server?
- Where will testing provide greatest value?
Lighthouse Scores
Lighthouse scores.
Key Metrics
These metrics are weighted to calculate the overall Lighthouse Performance score, with LCP and TBT having the biggest impact.
- First Contentful Paint (FCP) - measures when the first piece of content is rendered
- Speed Index (SI) - measures how quickly content is visually displayed
- Largest Contentful Paint (LCP) - measures when the largest content element is rendered
- Total Blocking Time (TBT) - measures the total time the main thread is blocked
- Cumulative Layout Shift (CLS) - measures unexpected layout shifts
Optimisation Tips
Tips to Optimize Next.js for 100% Lighthouse Scores:
- Image Optimization - Use Next.js's built-in Image component for automatic lazy loading, resizing, and modern formats like WebP.
- Code Splitting - Use Next.js's dynamic imports to split code into separate chunks loaded on-demand. This reduces work on the main thread.
- Static Site Generation - Use Next.js static generation to pre-render pages at build time, reducing server response times.
- Lazy Loading - Implement lazy loading for images and other non-critical content. Use skeleton loaders while content is fetched.
- CDN Usage - Deploy the Next.js app on a platform like Vercel that provides a global CDN for fast content delivery.
- Avoid Render-Blocking Resources - Eliminate render blocking CSS/JS and use code splitting to lazy load non-critical modules.
- Optimize Fonts - Subset fonts, use font-display, and preload key web fonts.
- Avoid Excessive DOM Size - Keep the DOM tree small and avoid too many elements/nesting.
- Efficient Hydration - Avoid blocking the main thread with excessive hydration of client-side JS.
Profiling
Profiling tools.
Architecture
Going serverless.