Modern Web Performance Optimization

Practical techniques for improving web performance, from lazy loading to code splitting.

Branislav Remeň
9 min read

Lead

Web performance isn't just about fast loading times—it's about creating experiences that feel instant and responsive. After optimizing sites that serve millions of users, I've learned which techniques actually move the needle and which are just vanity metrics.

Problem

Modern web applications are getting slower despite better infrastructure:

  • JavaScript bundles growing larger with each framework update
  • Third-party scripts blocking critical rendering paths
  • Unoptimized images consuming bandwidth unnecessarily
  • Poor caching strategies forcing repeated downloads

Users expect sub-3-second load times, but the average website takes over 10 seconds on mobile.

Steps

1. Measure First, Optimize Second

javascript
// lib/performance.ts
import { getCLS, getFID, getFCP, getLCP, getTTFB } from 'web-vitals'

function sendToAnalytics(metric) {
  analytics.track('web-vital', {
    name: metric.name,
    value: metric.value,
    rating: metric.rating,
  })
}

// Measure all Core Web Vitals
getCLS(sendToAnalytics)
getFID(sendToAnalytics)
getFCP(sendToAnalytics)
getLCP(sendToAnalytics)
getTTFB(sendToAnalytics)

Performance Budget: Set performance budgets: LCP < 2.5s, FID < 100ms, CLS < 0.1. Track these metrics in CI/CD.

2. Image Optimization Strategy

typescript
// components/OptimizedImage.tsx
import Image from 'next/image'
import { useState } from 'react'

export function OptimizedImage({ src, alt, width, height, priority = false }) {
  const [isLoading, setLoading] = useState(true)

  return (
    <div className="relative overflow-hidden">
      <Image
        src={src}
        alt={alt}
        width={width}
        height={height}
        priority={priority}
        className={`duration-700 ease-in-out ${
          isLoading
            ? 'scale-110 blur-2xl grayscale'
            : 'scale-100 blur-0 grayscale-0'
        }`}
        onLoadingComplete={() => setLoading(false)}
        sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
      />
    </div>
  )
}

Takeaways

Performance Hierarchy (in order of impact):

  1. Server Response Time - Fast backend beats any frontend optimization
  2. Critical Resource Loading - HTML, CSS, and above-the-fold content first
  3. Image Optimization - Usually the largest performance win
  4. JavaScript Bundle Size - Code splitting and tree shaking

Quick Wins:

  • Compress images (WebP/AVIF formats)
  • Enable gzip/brotli compression
  • Use a CDN for static assets
  • Implement lazy loading for below-the-fold content

Warning: Don't over-optimize. Focus on the biggest bottlenecks first. Use real user data, not synthetic benchmarks.

Subscribe to Pragmatic Web for more performance optimization techniques and real-world case studies.

Subscribe to Pragmatic Web

Get practical insights on web development, AI tools, and building things that matter. No fluff, just actionable content.

Subscribe Now