seekpik

Optimizing Assets for Web Performance

Learn how to optimize images, fonts, and other assets for fast-loading websites without sacrificing quality.

Why Asset Optimization Matters

Web performance directly impacts user experience, SEO rankings, and conversion rates. Studies show that 53% of mobile users abandon sites that take longer than 3 seconds to load. Optimizing your assets is crucial for:

  • Faster Page Load Times: Smaller files download quicker
  • Better SEO: Google prioritizes fast-loading sites
  • Improved User Experience: Smooth, responsive interactions
  • Reduced Bandwidth Costs: Lower hosting and CDN expenses
  • Mobile Performance: Critical for users on slower connections

Image Optimization Strategies

1. Choose the Right Format

  • WebP: Best overall choice - 25-35% smaller than JPEG/PNG with same quality
  • AVIF: Next-gen format - even better compression, but limited browser support
  • JPEG: Good for photos and complex images with many colors
  • PNG: Use for images requiring transparency or sharp edges
  • SVG: Perfect for logos, icons, and simple graphics - infinitely scalable

2. Compress Images Effectively

Compression reduces file size while maintaining acceptable quality:

  • Lossy Compression: Removes some data for smaller files (JPEG, WebP)
  • Lossless Compression: Reduces size without quality loss (PNG optimization)
  • Quality Settings: 80-85% quality is often indistinguishable from 100%
  • Tools: ImageOptim, TinyPNG, Squoosh, Sharp (Node.js)

3. Implement Responsive Images

Serve different image sizes based on device and screen resolution:

<img src="image-800w.jpg" srcset="image-400w.jpg 400w, image-800w.jpg 800w, image-1200w.jpg 1200w" sizes="(max-width: 600px) 400px, (max-width: 1200px) 800px, 1200px" alt="Responsive image" />

4. Use Lazy Loading

Load images only when they're about to enter the viewport:

<img src="image.jpg" loading="lazy" alt="Lazy loaded image" />

This reduces initial page load time and saves bandwidth for images users never see.

Font Optimization

1. Choose Modern Font Formats

  • WOFF2: Best compression, supported by all modern browsers
  • WOFF: Fallback for older browsers
  • Variable Fonts: Single file contains multiple weights/styles

2. Subset Your Fonts

Include only the characters you need. For English-only sites, you can reduce font file size by 70-80% by removing unused glyphs.

Tools for Font Subsetting:

  • • Google Fonts (automatic subsetting with text parameter)
  • • Glyphhanger (command-line tool)
  • • FontSquirrel Webfont Generator

3. Implement Font Loading Strategies

font-display Options:

  • swap: Show fallback immediately, swap when custom font loads (recommended)
  • optional: Use custom font only if it loads quickly, otherwise use fallback
  • fallback: Brief invisible period, then show fallback if font not loaded

4. Preload Critical Fonts

<link rel="preload" href="/fonts/main-font.woff2" as="font" type="font/woff2" crossorigin />

SVG Optimization

1. Clean Up SVG Code

Remove unnecessary metadata, comments, and hidden elements:

  • Use SVGO or SVGOMG to automatically optimize SVG files
  • Remove editor-specific data (Illustrator, Sketch metadata)
  • Simplify paths and reduce decimal precision
  • Remove unused IDs and classes

2. Inline Small SVGs

For icons and small graphics, inline SVG directly in HTML to eliminate HTTP requests and enable CSS styling.

3. Use SVG Sprites

Combine multiple SVG icons into a single sprite sheet to reduce HTTP requests.

Performance Best Practices

1. Use a CDN (Content Delivery Network)

Serve assets from servers geographically close to users for faster delivery. Popular CDNs: Cloudflare, Vercel, AWS CloudFront.

2. Enable Browser Caching

Set appropriate cache headers so browsers don't re-download unchanged assets. Use cache-busting techniques (versioned filenames) for updates.

3. Implement HTTP/2 or HTTP/3

Modern protocols allow multiplexing, reducing the overhead of multiple requests.

4. Minify CSS and JavaScript

Remove whitespace, comments, and unnecessary code from stylesheets and scripts.

5. Use Critical CSS

Inline CSS needed for above-the-fold content to eliminate render-blocking requests.

Optimization Checklist

Before Publishing:

  • ☐ Images compressed to appropriate quality level (80-85%)
  • ☐ Using modern formats (WebP, AVIF) with fallbacks
  • ☐ Responsive images implemented with srcset
  • ☐ Lazy loading enabled for below-the-fold images
  • ☐ Fonts subsetted and using WOFF2 format
  • ☐ Font-display: swap implemented
  • ☐ Critical fonts preloaded
  • ☐ SVGs optimized and cleaned
  • ☐ CDN configured for asset delivery
  • ☐ Browser caching headers set correctly
  • ☐ Performance tested with Lighthouse or WebPageTest

Testing and Monitoring

Performance Testing Tools

  • Google Lighthouse: Built into Chrome DevTools, comprehensive performance audit
  • WebPageTest: Detailed waterfall charts and performance metrics
  • GTmetrix: Easy-to-understand performance reports
  • PageSpeed Insights: Google's official tool with optimization suggestions

Key Metrics to Monitor

  • LCP (Largest Contentful Paint): Should be under 2.5 seconds
  • FID (First Input Delay): Should be under 100ms
  • CLS (Cumulative Layout Shift): Should be under 0.1
  • Total Page Size: Aim for under 1-2MB for initial load
  • Number of Requests: Fewer is better, aim for under 50

Common Mistakes to Avoid

❌ Using Unoptimized Images

Never upload images directly from cameras or design tools without compression.

❌ Loading All Fonts Upfront

Only load font weights and styles you actually use on the page.

❌ Ignoring Mobile Performance

Test on real mobile devices with throttled connections, not just desktop.

❌ Over-Optimizing

Don't sacrifice quality to the point where images look noticeably degraded.

Next Steps

Now that you understand web optimization, explore these related topics: