Modern Web Performance Optimization: Beyond the Basics

Deep dive into advanced web performance optimization techniques that can dramatically improve your site's Core Web Vitals and user experience.

By BrilliMinds Team
Modern Web Performance Optimization: Beyond the Basics

Modern Web Performance Optimization: Beyond the Basics

In 2025, web performance isn’t just about fast load times—it’s about delivering exceptional user experiences that directly impact your business metrics.

Google’s Core Web Vitals have become ranking factors, and users expect near-instant interactions. Studies show that a 100ms delay in load time can decrease conversion rates by 7%.

This guide explores advanced performance optimization techniques that go beyond the usual “minify and compress” advice. We’ll cover real-world strategies that have helped our clients achieve Google PageSpeed scores of 95+ while maintaining rich, interactive experiences.

Understanding the Performance Budget

Before optimizing, establish a performance budget:

// performance-budget.config.ts
export const PERFORMANCE_BUDGET = {
  // Timing budgets (ms)
  FCP: 1800,  // First Contentful Paint
  LCP: 2500,  // Largest Contentful Paint
  TTI: 3800,  // Time to Interactive
  TBT: 200,   // Total Blocking Time
  CLS: 0.1,   // Cumulative Layout Shift

  // Resource budgets (KB)
  javascript: 300,
  css: 100,
  images: 500,
  fonts: 100,
  total: 1000
};

Monitor these metrics in CI/CD to catch regressions early.

Advanced JavaScript Optimization

1. Code Splitting at the Route Level

Don’t just split by component—split by user journey:

// Next.js 14+ / React Router 6+
import { lazy } from 'react';

const routes = [
  {
    path: '/dashboard',
    component: lazy(() => import('./pages/Dashboard')),
    preload: () => import('./pages/Dashboard') // Prefetch on hover
  },
  {
    path: '/analytics',
    component: lazy(() => import('./pages/Analytics')),
    children: [
      {
        path: 'reports',
        component: lazy(() => import('./pages/Analytics/Reports'))
      }
    ]
  }
];

2. Aggressive Dead Code Elimination

Modern bundlers can eliminate more than you think:

// Use tree-shakeable imports
import { specific } from 'library'; // Good
import _ from 'lodash'; // Bad - imports everything

// Configure for production
export default {
  build: {
    rollupOptions: {
      treeshake: {
        moduleSideEffects: false,
        propertyReadSideEffects: false,
        tryCatchDeoptimization: false
      }
    }
  }
};

3. Web Workers for Heavy Computations

Offload expensive operations to prevent UI blocking:

// worker.ts
self.onmessage = async (e: MessageEvent) => {
  const { data, operation } = e.data;

  switch (operation) {
    case 'process-analytics':
      const result = await processLargeDataset(data);
      self.postMessage({ result });
      break;
  }
};

// main.ts
const worker = new Worker(new URL('./worker.ts', import.meta.url));

worker.postMessage({
  operation: 'process-analytics',
  data: largeDataset
});

worker.onmessage = (e) => {
  updateUI(e.data.result); // UI stays responsive
};

Image Optimization Strategies

1. Modern Format Adoption

Serve next-gen formats with fallbacks:

<picture>
  <source
    srcset="/image.avif"
    type="image/avif"
  />
  <source
    srcset="/image.webp"
    type="image/webp"
  />
  <img
    src="/image.jpg"
    alt="Fallback"
    loading="lazy"
    decoding="async"
  />
</picture>

2. Responsive Images Done Right

Don’t just use srcset—optimize for actual display sizes:

// Image CDN configuration
const optimizedImage = (src: string, width: number) => {
  return `https://cdn.example.com/${src}?w=${width}&q=80&format=auto`;
};

// Component
<img
  srcset={`
    ${optimizedImage(src, 320)} 320w,
    ${optimizedImage(src, 640)} 640w,
    ${optimizedImage(src, 1024)} 1024w,
    ${optimizedImage(src, 1920)} 1920w
  `}
  sizes="(max-width: 320px) 280px,
         (max-width: 640px) 600px,
         (max-width: 1024px) 980px,
         1200px"
  src={optimizedImage(src, 1024)}
  alt="Description"
/>

3. Lazy Loading with Intersection Observer

More control than native lazy loading:

class LazyLoader {
  private observer: IntersectionObserver;

  constructor() {
    this.observer = new IntersectionObserver(
      (entries) => {
        entries.forEach(entry => {
          if (entry.isIntersecting) {
            this.loadImage(entry.target as HTMLImageElement);
            this.observer.unobserve(entry.target);
          }
        });
      },
      {
        rootMargin: '50px', // Load 50px before entering viewport
        threshold: 0.01
      }
    );
  }

  observe(img: HTMLImageElement) {
    this.observer.observe(img);
  }

  private loadImage(img: HTMLImageElement) {
    const src = img.dataset.src;
    if (src) {
      img.src = src;
      img.removeAttribute('data-src');
    }
  }
}

Optimizing Core Web Vitals

Improving LCP (Largest Contentful Paint)

Identify and optimize your LCP element:

// Detect LCP element
const observer = new PerformanceObserver((list) => {
  const entries = list.getEntries();
  const lastEntry = entries[entries.length - 1];

  console.log('LCP element:', lastEntry.element);
  console.log('LCP time:', lastEntry.startTime);
});

observer.observe({ entryTypes: ['largest-contentful-paint'] });

Optimization strategies:

  1. Preload critical resources:
<link rel="preload" as="image" href="/hero.webp" fetchpriority="high">
  1. Optimize server response time:
// Edge caching with Cloudflare Workers
export default {
  async fetch(request) {
    const cache = caches.default;
    let response = await cache.match(request);

    if (!response) {
      response = await fetch(request);
      // Cache for 1 hour
      const headers = new Headers(response.headers);
      headers.set('Cache-Control', 's-maxage=3600');

      response = new Response(response.body, {
        status: response.status,
        headers
      });

      await cache.put(request, response.clone());
    }

    return response;
  }
};

Minimizing CLS (Cumulative Layout Shift)

Reserve space for dynamic content:

/* Reserve space for images */
.image-container {
  aspect-ratio: 16 / 9;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* Reserve space for web fonts */
.text {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  /* Size-adjust for custom font to match system font metrics */
  size-adjust: 95%;
}

Reducing TBT (Total Blocking Time)

Break up long tasks:

// Bad: Blocks main thread for 500ms
function processItems(items: Item[]) {
  items.forEach(item => expensiveOperation(item));
}

// Good: Yields to browser between batches
async function processItems(items: Item[]) {
  const BATCH_SIZE = 50;

  for (let i = 0; i < items.length; i += BATCH_SIZE) {
    const batch = items.slice(i, i + BATCH_SIZE);
    batch.forEach(item => expensiveOperation(item));

    // Yield to browser
    await new Promise(resolve => setTimeout(resolve, 0));
  }
}

Network Optimization

1. HTTP/3 and Early Hints

// Server with HTTP/3 support
import { createServer } from 'http3';

const server = createServer((req, res) => {
  // Send early hints for critical resources
  res.writeEarlyHints({
    link: [
      '</styles/critical.css>; rel=preload; as=style',
      '</scripts/main.js>; rel=preload; as=script'
    ]
  });

  // ... rest of response
});

2. Resource Hints Strategy

<!-- Preconnect to required origins -->
<link rel="preconnect" href="https://api.example.com">
<link rel="preconnect" href="https://cdn.example.com">

<!-- DNS prefetch for third-party resources -->
<link rel="dns-prefetch" href="https://analytics.google.com">

<!-- Prefetch next likely navigation -->
<link rel="prefetch" href="/likely-next-page">

Monitoring and Continuous Improvement

Implement real user monitoring (RUM):

// Track Core Web Vitals
import { getCLS, getFID, getFCP, getLCP, getTTFB } from 'web-vitals';

function sendToAnalytics(metric: Metric) {
  fetch('/api/analytics', {
    method: 'POST',
    body: JSON.stringify({
      name: metric.name,
      value: metric.value,
      rating: metric.rating,
      delta: metric.delta,
      id: metric.id
    }),
    keepalive: true
  });
}

getCLS(sendToAnalytics);
getFID(sendToAnalytics);
getFCP(sendToAnalytics);
getLCP(sendToAnalytics);
getTTFB(sendToAnalytics);

Conclusion

Modern web performance optimization is an ongoing process that requires measurement, iteration, and attention to detail. By implementing these advanced techniques, you can achieve:

  • 50-70% reduction in JavaScript bundle sizes
  • 2-3x faster Time to Interactive
  • Near-zero Cumulative Layout Shift
  • Improved SEO rankings and user engagement

At BrilliMinds, we’ve helped clients achieve Google PageSpeed scores of 95+ while maintaining rich, interactive user experiences. Contact us to learn how we can optimize your application.

Tools We Use

  • Lighthouse CI - Automated performance testing
  • WebPageTest - Real-world performance analysis
  • Chrome DevTools - Performance profiling
  • Sentry - Real user monitoring
  • Bundle Analyzer - JavaScript optimization

About the author

BrilliMinds Team

BrilliMinds Team

Software Engineering & Product Team

BrilliMinds Team shares practical insights on software architecture, AI integration, product delivery, and engineering best practices for startups and enterprises.