Insights:What Is Image & Static Resource Optimization? A Visual Explanation
How Images Slow Down Pages
- The browser encounters an image tag and sends a request.
- The server returns the original image (possibly 4000px wide).
- Only after downloading does the browser decode, scale, and display it.
The problem is: the original image is downloaded, but only a thumbnail is displayed. All the extra bytes are wasted.
Four Key Optimization Elements
| Element | Approach | Benefit |
|---|---|---|
| Size matching | Generate images at display width, including 2x density | Greatest reduction in file size |
| Format selection | Use WebP/AVIF for photos, SVG for icons | Additional 20%–50% reduction |
| Quality compression | Visually lossless range (e.g., 75–85) | Significant size decrease |
| Lazy loading | Defer loading for off-screen images | Faster first screen render |
How to Choose Formats
- JPEG: Best compatibility, suitable for photos, but larger file sizes.
- WebP: Well-supported by mainstream browsers, smaller at the same quality.
- AVIF: Highest compression ratio, but slower encoding and moderate compatibility.
- PNG: Ideal for transparent or low-color images; photos in PNG can be very large.
- SVG: First choice for icons and vector graphics; scalable and extremely lightweight.
Practical recommendation: use WebP for main images, SVG for icons, and PNG when transparency with complex colors is required.
How to Achieve Size Matching
- First, determine the display area width (e.g., 360px for list thumbnails).
- Provide a 1× image at 360px and a 2× image at 720px.
- Use
srcsetso the browser picks the right variant for the screen.
Avoid using a single 2000px original image scaled down to 360px—that’s the most common waste.
Proper Use of Lazy Loading
- Above-the-fold images should not be lazy-loaded, which would slow down first paint.
- For images below the fold, use
loading="lazy". - Always set explicit width and height on images to prevent layout shift during loading.
Caching & File Names
- Set long cache durations for static assets (e.g., one year).
- When images are updated, change the file name (add a hash or version suffix) so users don’t see stale images.
- Never append random query parameters to bypass caching.
Common Mistakes
- Compressing quality only, not size: mismatched dimensions limit the benefit of compression.
- Converting everything to AVIF: some environments don’t support it, increasing fallback cost.
- Lazy-loading above-the-fold images: slows first paint and worsens experience.
- Not specifying width/height on images: causes layout shift and hurts experience metrics.
Limits
Image optimization can significantly improve load speed and experience metrics, but it won’t fix a slow server response. If TTFB is high, check the backend and caching first.
Related reading:
- Image Asset Optimization: Priority Order — What to Do First and What Comes Next
- Page Cache and CDN Basics — Explained with a Diagram