<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: wu ruihua</title>
    <description>The latest articles on DEV Community by wu ruihua (@wu_ruihua_bbdb65cdbde7b48).</description>
    <link>https://dev.to/wu_ruihua_bbdb65cdbde7b48</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4245940%2Fa3991348-91d7-4348-b8da-c831561b53b2.png</url>
      <title>DEV Community: wu ruihua</title>
      <link>https://dev.to/wu_ruihua_bbdb65cdbde7b48</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wu_ruihua_bbdb65cdbde7b48"/>
    <language>en</language>
    <item>
      <title>Building a Browser-Only Image Compressor: What We Actually Measured</title>
      <dc:creator>wu ruihua</dc:creator>
      <pubDate>Sun, 15 Nov 2026 12:44:22 +0000</pubDate>
      <link>https://dev.to/wu_ruihua_bbdb65cdbde7b48/building-a-browser-only-image-compressor-what-we-actually-measured-1l26</link>
      <guid>https://dev.to/wu_ruihua_bbdb65cdbde7b48/building-a-browser-only-image-compressor-what-we-actually-measured-1l26</guid>
      <description>&lt;p&gt;Building a Browser-Only Image Compressor: What We Actually Measured&lt;/p&gt;

&lt;p&gt;Most "online image compressor" pages upload your file, compress it on a server, and hand back a download link. That works, but it costs you two things: your file leaves your machine, and the result depends on someone else's queue depth.&lt;/p&gt;

&lt;p&gt;We wanted the opposite: the pixels never leave the browser. Here is what that looks like in practice, and what the measurements actually say.&lt;/p&gt;

&lt;p&gt;Why "local" is an architecture decision, not a promise&lt;/p&gt;

&lt;p&gt;A privacy claim is only as good as its architecture. If a page uploads your image, "we delete it in 24 hours" is policy. If a page never uploads, there is nothing to delete.&lt;/p&gt;

&lt;p&gt;The verification is trivial: open the page, disconnect the network, drop an image in, and see whether a result comes out. If it does, the work happened in the tab.&lt;/p&gt;

&lt;p&gt;What runs inside the tab&lt;/p&gt;

&lt;p&gt;Encoding is handled by WebAssembly builds of established encoders, and pixel work runs on Canvas:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PNG, lossy: pngquant (derived from Squoosh)&lt;/li&gt;
&lt;li&gt;PNG, lossless: OxiPNG (Rust)&lt;/li&gt;
&lt;li&gt;JPEG: MozJPEG, wrapped as WASM&lt;/li&gt;
&lt;li&gt;WebP: libwebp&lt;/li&gt;
&lt;li&gt;AVIF: libaom&lt;/li&gt;
&lt;li&gt;GIF/APNG: per-frame quantization plus repacking&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No model inference, no cloud GPU, no heuristics learned from data. Same input, same parameters, same output, every time.&lt;/p&gt;

&lt;p&gt;The measurement table&lt;/p&gt;

&lt;p&gt;Five representative inputs, all processed with the same build:&lt;/p&gt;

&lt;p&gt;Input | Original | Lossless | Quantized | WebP&lt;br&gt;
Transparent PNG icon 800x600 | 5.3 KB | 4.3 KB (-18.6%) | 3.3 KB (-37.6%) | 6.1 KB (larger)&lt;br&gt;
Camera JPEG 2000x1500 q95 | 1.54 MB | - | q75: 374 KB (-76.2%) | -&lt;br&gt;
UI screenshot 1920x1080 | 9.6 KB | 9.3 KB (-2.2%) | 2.8 KB (-70.3%) | -&lt;br&gt;
Full-color PNG 1600x1200 | 473.7 KB | 375.5 KB (-20.7%) | 55.8 KB (-88.2%) | 16.1 KB (-96.6%)&lt;br&gt;
GIF 400x400, 12 frames | 21.8 KB | - | 92.4 KB (larger) | 61.8 KB (larger)&lt;/p&gt;

&lt;p&gt;Three conclusions worth keeping&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The gain depends on the route, not the tool. A transparent 5 KB icon can get &lt;em&gt;bigger&lt;/em&gt; if you route it to WebP, because the container overhead eats the savings. The same icon quantized saves 37%.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Screenshots belong on the quantized route. Lossless optimization on a 1920x1080 UI capture saves 2%; palette quantization saves 70% with no visible difference at 100% zoom.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Format flexibility is worth more than encoder tuning. Allowing WebP on full-color art took the result from 55.8 KB to 16.1 KB. Users who insist on "keep PNG" cut their own ceiling in half.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Where it breaks&lt;/p&gt;

&lt;p&gt;Large images are limited by the device, not the code. A 4000x3000 photo takes 3-5 seconds on a low-end phone and under a second on a desktop. Peak memory is roughly concurrency × decoded bitmap × 2, so a four-way batch on 48 MB bitmaps can approach 400 MB and trigger GC churn.&lt;/p&gt;

&lt;p&gt;Batching is the real weak point. Without a server there is no API, so bulk work means dragging files by hand. If you need an unattended pipeline, use command-line tools (oxipng, jpegoptim, ImageMagick) or a service with an endpoint. Browser-local is for a handful of files at a time.&lt;/p&gt;

&lt;p&gt;What we'd optimize next&lt;/p&gt;

&lt;p&gt;Downscale before encoding. Worker pools with OffscreenCanvas. Concurrency at half the physical core count. And a three-stage progress indicator (decode, encode, package) — because past about twenty files the bottleneck stops being CPU and becomes feedback.&lt;/p&gt;

&lt;p&gt;Measurements above come from our own runs on the same algorithm family, and are meant as an upper-bound reference for what each route can achieve in a browser — not a guarantee for every input. If you want to check them, open the tool, disconnect, and run your own images.&lt;/p&gt;

&lt;p&gt;The broader point is simple: for a specific, bounded class of tasks, the browser is now a legitimate compute target. The constraint is not whether it can run — it is whether you are willing to design for the device you do not control.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>performance</category>
      <category>webassembly</category>
    </item>
  </channel>
</rss>
