Mobile devices now account for over 60% of web traffic, yet many sites still serve desktop-sized images to mobile users. Mobile optimization is critical for user experience, data costs, and SEO.
The Mobile Challenge
Mobile devices face unique constraints: smaller screens, slower connections, data caps, and less processing power. A 2MB image that loads acceptably on desktop WiFi can take 10+ seconds on a 3G mobile connection.
Mobile users are also more likely to abandon slow sites. Google's research shows that 53% of mobile users leave pages that take longer than 3 seconds to load.
Responsive Images: The Foundation
Use the srcset attribute to serve different image sizes based on screen width:
<img src="image-800.jpg"
srcset="image-400.jpg 400w,
image-800.jpg 800w,
image-1200.jpg 1200w"
sizes="(max-width: 600px) 400px,
(max-width: 900px) 800px,
1200px"
alt="Description">
Browsers automatically select the most appropriate size. A phone displays the 400px version, tablets get 800px, and desktops receive 1200px.
Device Pixel Ratio Considerations
Modern phones have high pixel density displays (2x or 3x). However, serving 3x images to mobile isn't always optimal.
Consider serving 1.5x images to mobile. The difference between 1.5x and 3x is imperceptible on small screens, but file sizes can be 50% smaller.
Format Selection for Mobile
WebP support on mobile browsers is excellent (95%+ coverage). Serve WebP to mobile users for 25-35% file size savings over JPEG.
Use the picture element for format fallbacks:
<picture>
<source srcset="image.webp" type="image/webp">
<img src="image.jpg" alt="Description">
</picture>
Compression for Mobile Networks
Mobile users often tolerate slightly lower quality in exchange for faster loading. Consider more aggressive compression for mobile:
- Desktop: 85% quality
- Mobile: 75% quality
Use media queries or client hints to detect mobile devices and serve appropriately compressed images.
Lazy Loading on Mobile
Lazy loading is especially important on mobile where data and processing power are limited. Use native lazy loading:
<img src="image.jpg" loading="lazy" alt="Description">
This defers loading offscreen images, reducing initial page weight and improving perceived performance.
Client Hints and Adaptive Serving
Client Hints allow servers to adapt image delivery based on device capabilities:
Accept-CH: DPR, Viewport-Width, Width
With Client Hints enabled, your server can dynamically generate optimal images for each request without client-side JavaScript.
Progressive Enhancement
Use progressive JPEGs for mobile. They display a low-quality preview immediately, then progressively enhance as more data arrives. This provides better perceived performance.
Thumbnail Strategies
For image galleries on mobile, use tiny placeholder thumbnails (100-200 bytes) that load instantly, then load full images on-demand when users interact.
<img src="placeholder.jpg"
data-src="full-size.jpg"
loading="lazy">
Testing Mobile Performance
Test on real devices and connections. Chrome DevTools can throttle network speed, but real-world testing is essential.
Use Google's Mobile-Friendly Test and PageSpeed Insights Mobile score. Aim for:
- LCP under 2.5 seconds
- Total page weight under 1 MB
- First Contentful Paint under 1.8 seconds
Data Saver Mode
Detect Data Saver mode (Save-Data header) and serve even lighter images:
if (request.headers['save-data'] === 'on') {
// Serve more compressed versions
}
Respect users' preferences to minimize data usage.