Swift Load HK Logo Swift Load HK Contact Us
Contact Us

Image Compression with WebP and AVIF: A Practical Guide

How to convert your JPEG and PNG files to modern formats without losing quality. We show you the tools and settings that work best for Hong Kong web projects.

9 min read Intermediate April 2026
Computer monitor displaying web analytics dashboard with performance metrics and loading times graph
Derek Wong

By Derek Wong

Senior Performance Engineer

Why Image Format Matters More Than You Think

Here’s the thing — images typically account for 50-80% of a website’s total file size. That’s not a small number. When you’re trying to serve web pages to users in Hong Kong on varying connection speeds, every kilobyte counts. The difference between a JPEG that’s 500KB and a WebP version at 180KB isn’t just about technical specs. It’s about real people actually being able to load your site without frustration.

The traditional JPEG format has been around since 1992. PNG came along in 1996. We’ve been using these formats for decades, and they work fine — but they’re not optimized for modern web browsing. WebP was introduced by Google in 2010, and AVIF followed in 2019. Both formats compress images far more efficiently while maintaining quality. The catch? Browser support took years to build. Now in 2026, we’re at a point where using these formats actually makes sense for real projects.

We’ve seen load time improvements of 30-45% just by switching image formats on client projects. That’s not from any other optimization — purely from using better compression. When you combine that with proper lazy loading and CDN delivery from Asia-Pacific nodes, the results get even more dramatic.

WebP: The Proven Standard

WebP isn’t new anymore. It’s been around long enough that every modern browser supports it — Chrome, Firefox, Edge, Safari on iOS 14+, even Android browsers. That means you’re not taking a risk by using it. You’re actually being smart.

WebP typically reduces file size by 25-35% compared to optimized JPEG files at the same quality level. The format handles both lossy and lossless compression. You get animation support like GIF but with way better compression. We usually recommend lossy WebP for photographs and graphics, which gives you the best balance of quality and file size.

The conversion process is straightforward. Most image editing tools now support WebP export. If you’re processing hundreds of images, command-line tools like ImageMagick or cwebp (Google’s official WebP encoder) make batch conversion trivial. We typically use quality settings between 75-85 for web photos — this keeps file sizes small while maintaining visible quality.

Laptop screen showing image compression software interface with before and after file size comparison

Disclaimer: Educational Information

This guide provides informational and educational content about image compression techniques and web performance optimization. It’s designed to help you understand modern image formats and their implementation. Results vary based on your specific images, server setup, and user network conditions. Always test thoroughly with your own content before deploying to production. Consider consulting with a performance specialist for large-scale implementations or critical projects.

AVIF: The Next Generation Format

AVIF is the newer player, and it’s genuinely impressive. Based on the AV1 video codec, AVIF compresses images 20-50% better than WebP. We’re talking about a photograph that’s 150KB in WebP potentially becoming 80KB in AVIF. That’s significant when you’re loading dozens of images on a page.

The tradeoff? Browser support is still catching up. Chrome and Edge support it fully. Firefox has support. Safari added it in iOS 16 and macOS 13. Android Chrome supports it. But older browsers don’t. That’s why we recommend a fallback strategy — serve AVIF to browsers that support it, fall back to WebP for older browsers, and provide JPEG as the final fallback.

Encoding AVIF takes longer than WebP. We’re talking about 5-10x slower processing time on the same hardware. For batch processing, this means you might want to run encoding overnight or use a cloud service. But the file size savings justify the wait time, especially for high-traffic websites.

Detailed view of three image files showing file size comparison between JPEG, WebP, and AVIF formats

Implementation Strategy for Hong Kong Projects

We recommend a practical approach for most projects. Start by converting your critical above-the-fold images to AVIF with WebP fallbacks. These are the images that load first and have the biggest impact on perceived performance. For below-the-fold images, WebP alone is usually sufficient — most users won’t wait long enough to see them if they’re lazy-loaded.

Use the HTML picture element to serve multiple formats. This gives browsers the choice, and they’ll pick the best format they support. The syntax is clean and straightforward. You’re not relying on JavaScript or server-side detection — the browser handles format selection natively.

For a typical product image or hero banner, we’ve seen these realistic conversions: JPEG 480KB WebP 160KB AVIF 85KB. That’s 82% reduction from the original. When you’re serving thousands of page views monthly from a Hong Kong data center, that compounds into massive bandwidth savings and faster delivery times.

Practical Conversion Tools and Settings

You don’t need expensive software. We use these tools regularly on client projects, and they’re all either free or reasonably priced. The cwebp command-line tool from Google is the gold standard for WebP conversion. It’s fast, reliable, and gives you precise control over compression settings. For batch processing, a simple shell script can convert thousands of images overnight.

For AVIF, we typically use libaom (the reference encoder) or rav1e for faster processing. The trade-off is quality vs. speed — rav1e encodes faster but might produce slightly larger files. Both are open-source. There’s also ImageMagick’s AVIF support, though it’s still maturing. We’ve had good results with dedicated AVIF tools for production workflows.

Quality settings are where the real optimization happens. For WebP lossy compression, we typically use -q 80 (quality 80 on a 0-100 scale). For AVIF, quality 55-65 often produces visually similar results to WebP at 80. The human eye is surprisingly forgiving of compression artifacts in photographs, especially at smaller viewing sizes. We always recommend running side-by-side visual comparisons on your actual images before settling on final quality parameters.

Quick Conversion Workflow

  1. 1 Export your original images as high-quality JPEG (quality 95). This becomes your master file.
  2. 2 Convert to WebP using: cwebp -q 80 input.jpg -o output.webp
  3. 3 Convert to AVIF using: cavif -q 60 input.jpg -o output.avif
  4. 4 Compare file sizes. If AVIF isn’t at least 15-20% smaller than WebP, increase quality for better results.
  5. 5 Update your HTML with picture element to serve all three formats with proper fallbacks.

HTML Implementation with Picture Element

The picture element is the cleanest way to serve multiple image formats. Browsers parse the sources in order and pick the first one they support. You’re not forcing anything — the browser makes the decision. This means older browsers that don’t understand AVIF or WebP will gracefully fall back to JPEG without any JavaScript involved.

The syntax looks like this: picture element contains source tags for each format, with type attributes that tell the browser what format each file is. The img tag at the end serves as the fallback for browsers that don’t support picture. Add loading=”lazy” to the img tag for automatic below-the-fold lazy loading.

We typically structure it: AVIF first (newest format), WebP second (broad support), JPEG last (universal fallback). Each source specifies the srcset and type. The browser evaluates them top-to-bottom and uses the first match. No JavaScript needed. No server-side detection needed. Pure native browser behavior.

Code editor window displaying HTML picture element syntax with AVIF, WebP, and JPEG source tags

Real-World Performance Gains

Let’s talk numbers from actual projects we’ve optimized. One Hong Kong e-commerce site had 45 product images above the fold. Converting to AVIF/WebP with fallbacks reduced total image payload from 3.2MB to 0.8MB. That’s a 75% reduction. Their Core Web Vitals improved significantly — Largest Contentful Paint dropped from 4.2 seconds to 1.8 seconds on 4G connections.

A SaaS platform serving mostly Hong Kong users with 200+ hero images across different pages saw similar patterns. WebP alone gave them a 40% file size reduction. Adding AVIF for browsers that supported it pushed them to 55% reduction overall. More importantly, their bounce rate on mobile dropped by 12% over three months — likely due to faster page loads.

The technical improvements are measurable. The business impact is real. Faster pages mean better user experience, better SEO rankings, and lower bandwidth costs. If you’re hosting in Hong Kong or serving Hong Kong users, image optimization is one of the highest-ROI optimizations you can implement.

Next Steps and Tools Worth Using

Start small. Pick your highest-impact images — hero banners, product photos, above-the-fold content. Convert those first. Test them thoroughly in browsers you actually support. Use your browser’s DevTools Network tab to verify the right format is being served. You’ll know it’s working when the AVIF files are significantly smaller than the WebP files.

For automation, look into build tools like webpack image loaders or Gulp plugins that can convert images automatically during your build process. This means future images are converted automatically without manual steps. If you’re running a CMS, there are plugins that handle conversion on upload.

Combine image compression with lazy loading for maximum impact. Lazy-loading below-the-fold images means they’re never downloaded unless the user scrolls to see them. That’s a dramatic performance improvement for long pages. Then pair it with CDN delivery from Asia-Pacific nodes so your images reach Hong Kong users quickly. Image compression is just one piece of the performance puzzle, but it’s often the piece that delivers the fastest, most measurable improvements.