PERFORMACE - rs-hash/Senior GitHub Wiki
-
Initial Assessment and Benchmarking:
Start by mentioning the importance of conducting an initial assessment of the application's current performance using tools like Lighthouse, PageSpeed Insights, or WebPageTest, Crux. - benchmark key performance metrics such as
load time
,time to interactive
,first contentful paint
, andoverall page size
. -
core web vitals
:'LCP, INP, CLS`, Loading, interactivity, stability - elements affect LCP :
image
,block
,video
,background-image
- improve LCP :
responsive images
,compress
,WebP
,image cdn
,server-push
- push critical content by server,http2
- Improve CLS -
width, height
,skeleton pattern
,reserved space for banners & dynamic content
aspect-ratio
for images, use low resolution placeholder images till it loads - optimizing code, such as
minification
,compression
, andtree shaking
to reduce file sizes and improve load times. -
code splitting
andbundling
strategies using tools likeWebpack
to reduce initial load times -
Webpack, Rollup
: Bundlers to optimize and bundle JavaScript, CSS, and assets for production. -
Code splitting
: Technique to split the code into smaller chunks and load them on demand, improving initial load times. -
Service Workers
: Utilized for caching assets and enabling offline functionality. - Remove unused css
purgeCSSPlugin
- Highlight the importance of
optimizing images
and other media assets using formats likeWebP
,lazy loading
, andresponsive image
techniques. -
optimize images and media
- WebP, lazy load,src-set
,size
s, compress,loading='lazy'
,react-lazy-load-image-component
, placeholder image, blur -
Image optimization tools
: Tools like ImageMagick, Squoosh, or services like Cloudinary for optimizing images to reduce file size without compromising quality. - Explain how
optimizing the critical rendering path
byminimizing render-blocking resources
, leveragingbrowser caching
- inlining
critical CSS
anddeferring non-critical CSS and JavaScript
toprioritize above-the-fold content
and reduce render-blocking. Virtualize large lists
- Performance hooks in React
- Server side rendering - Next.js
-
Preload
critical resources (e.g., above-the-fold content, essential scripts) andprefetch
related resources (e.g., next page content, linked assets) to proactively load content and reduce perceived latency.
- Intermediate proxy servers or
content delivery networks (CDNs)
can cache resources on behalf of clients. These caches arecloser to the user's location
, reducing latency and server load. -
Server-Side Cache
: Web servers can cache dynamic content or API responses to serve subsequent requests more quickly. Caching mechanisms like Memcached,Redis
, or built-in server caching tools (e.g., NGINX caching) are used for this purpose. - HTTP headers such as
Cache-Control
are used to control caching behavior. They specify directives likemax-age
,no-cache
,no-store
,public
,private
, andmust-revalidate
to instruct browsers and proxies on how to cache and handle cached content. - Cached content needs to be invalidated or refreshed periodically to ensure that users receive updated information. Techniques like
cache expiration
(setting max-age or expires headers
), cache busting (using unique query parameters or versioning), and manual cache purging are used forcache invalidation.
- optimizing network requests by reducing the number of HTTP requests, using
HTTP/2 for multiplexing
andserver push
, and implementing resource hints likepreload
andprefetch
. - server-side optimizations such as caching, CDN (Content Delivery Network) utilization, and Gzip compression to improve response times and reduce latency.
- Implement
load balancing
todistribute incoming traffic across multiple servers
and improve application scalability. Use horizontal scaling (adding more servers) and vertical scaling (increasing server resources) to handle increased load. - Enable compression (e.g., gzip, Brotli) for text-based assets like HTML, CSS, JavaScript, and JSON to reduce file sizes and improve transfer speeds
"You can't improve what you don't measure."
Tools:
-
Google Lighthouse / Chrome DevTools Audits
-
WebPageTest, GTmetrix
-
Chrome Performance tab
-
Core Web Vitals (CWV): Largest Contentful Paint (LCP), First Input Delay (FID), Cumulative Layout Shift (CLS)
-
Real User Monitoring (RUM): New Relic, Datadog, Sentry, SpeedCurve
What to Look For:
-
Slow Time to First Byte (TTFB)
-
High LCP (>2.5s)
-
Render-blocking resources
-
Large JavaScript bundles
-
Layout shifts or long input delays
- β 2.1 Minify and Compress
Minify JS, CSS, and HTML (via Webpack, Terser, UglifyJS)
Use Gzip or Brotli compression on server
- β 2.2 Use Efficient Image Formats
Convert to WebP, AVIF
Use responsive images with srcset
Use image CDNs (e.g., Cloudinary, Imgix)
- β 2.3 Lazy Load Images and Components
Native loading="lazy" for
Lazy load components in frameworks (React.lazy, Vue async components)
- β 3.1 Code Splitting
Split code by route or component
Use dynamic imports: import() in React, Vue, Angular
- β 3.2 Tree Shaking
Remove dead code (ensure libraries support ES Modules)
Use sideEffects flag in package.json
- β 3.3 Avoid Unused Dependencies
Audit with webpack-bundle-analyzer, source-map-explorer
Replace large libs (e.g., lodash) with smaller utilities (e.g., lodash-es, native functions)
- β 3.4 Defer and Async Scripts
defer for JS scripts that donβt block rendering
async for independent scripts (analytics, ads)
- β 4.1 Reduce Critical CSS
Inline critical CSS for above-the-fold content
Load the rest asynchronously
- β 4.2 Eliminate Render-Blocking Resources
Move CSS to head (minified), JS to end of body (deferred)
- β 4.3 Preload Key Resources
Fonts ()
Images
Hero content (e.g., banner image)
- β 5.1 Browser Caching
Set far-future Cache-Control headers for static assets
Use cache busting (e.g., filename.[hash].js)
- β 5.2 Service Workers
Implement caching strategies: stale-while-revalidate, cache-first
Use Workbox for PWA support
- β 6.1 Skeleton Screens and Spinners
Show UI placeholders instead of blank screen
Improve First Contentful Paint (FCP) perception
- β 6.2 Progressive Hydration (React, Next.js)
Only hydrate interactive parts as needed
- β 6.3 Avoid Long Main Thread Tasks
Split heavy JS execution into chunks
Use requestIdleCallback or setTimeout to defer non-critical logic
- β 7.1 Reduce HTTP Requests
Combine small assets (icons into SVG sprite)
Remove unnecessary polyfills
- β 7.2 HTTP/2 or HTTP/3
Multiplex requests
Better header compression, faster TLS handshake
- β 7.3 Debounce or Throttle API Calls
Avoid overloading the client or server
Prevent excessive re-renders
- β 7.4 API Response Optimization
Compress API responses (Gzip, Brotli)
Avoid overfetching; use GraphQL or selective REST endpoints
- Step 8: Use a CDN and Global Edge Network β Content Delivery Network (CDN)
Serve static assets close to users
Reduce latency for global users
React
Use React.memo, useMemo, useCallback effectively
Avoid prop drilling
Use Suspense for data fetching
Enable concurrent features (React 18+)
Vue
- Use computed properties instead of methods
- Avoid deep watching
- Use dynamic component loading
Next.js
- Enable Image Optimization
- Use Static Site Generation (SSG) where possible
- Use next/script for optimized script loading
Set up performance budgets
Monitor Core Web Vitals using RUM tools
Run automated Lighthouse audits in CI/CD pipelines
Use tools like Calibre, SpeedCurve, or GitHub Actions for performance regression testing
π ### Continuous Loop: Audit β Optimize β Monitor β Repeat Treat performance like security β it's not one-and-done.
Profile and test across different devices and network conditions.
Balance between developer productivity, performance, and maintainability.
π§ Bonus: Advanced Performance Techniques
HTTP caching headers (ETag, Last-Modified)
Web Workers for heavy computations
Priority Hints (importance="high")
Font Subsetting
Quicklink prefetching for next-page navigation