<?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: lane</title>
    <description>The latest articles on DEV Community by lane (@_53aff61a6f7bb8c043b33).</description>
    <link>https://dev.to/_53aff61a6f7bb8c043b33</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%2F4193536%2F4743fbb0-478e-4423-9bf8-edd62c368466.png</url>
      <title>DEV Community: lane</title>
      <link>https://dev.to/_53aff61a6f7bb8c043b33</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/_53aff61a6f7bb8c043b33"/>
    <language>en</language>
    <item>
      <title>No-Upload File Conversion in the Browser: An Architecture Walkthrough</title>
      <dc:creator>lane</dc:creator>
      <pubDate>Mon, 19 Oct 2026 08:03:06 +0000</pubDate>
      <link>https://dev.to/_53aff61a6f7bb8c043b33/no-upload-file-conversion-in-the-browser-an-architecture-walkthrough-8n1</link>
      <guid>https://dev.to/_53aff61a6f7bb8c043b33/no-upload-file-conversion-in-the-browser-an-architecture-walkthrough-8n1</guid>
      <description>&lt;p&gt;Most "free online converters" upload your file to a server, convert it there, and hand you a download link. If you've ever converted a client mockup, a signed contract, or an unreleased screenshot, that's a quiet problem: your file passes through infrastructure you don't control, usually with a "we delete it after 24 hours" promise you can't verify.&lt;/p&gt;

&lt;p&gt;I wanted a converter I could actually trust for that kind of file, so I built one that never uploads anything. Along the way I hit a few non-obvious problems — CSP and HEIC, EXIF rotation, worker timeouts, and target-size compression. Here's what I learned.&lt;/p&gt;

&lt;h2&gt;
  
  
  "No upload" should be verifiable, not a marketing claim
&lt;/h2&gt;

&lt;p&gt;The nice thing about a fully client-side converter is that you can check the claim in ten seconds:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open the tool.&lt;/li&gt;
&lt;li&gt;Open DevTools → Network and tick &lt;em&gt;Preserve log&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Drop in a file and convert it.&lt;/li&gt;
&lt;li&gt;Filter by Fetch/XHR.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You won't see a request carrying your file — only the initial page assets. That's possible because the deployed artifact is a static bundle of HTML, CSS, JS and WASM on a CDN. There is no upload endpoint to log, because there is no backend.&lt;/p&gt;

&lt;h2&gt;
  
  
  The image pipeline
&lt;/h2&gt;

&lt;p&gt;Conversion is decode → draw → encode.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Decode&lt;/strong&gt; with &lt;code&gt;createImageBitmap(blob, { imageOrientation: 'from-image' })&lt;/code&gt;. That applies the EXIF rotation, so portrait phone photos don't come out sideways. Some browsers ignore the option, so I fall back to the plain call.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Draw&lt;/strong&gt; to an offscreen canvas. For JPEG output, fill the canvas white first. JPEG has no alpha channel, and without that fill, transparent pixels render black.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Encode&lt;/strong&gt; the pixels. The tempting API is &lt;code&gt;canvas.toBlob()&lt;/code&gt;, but it produces poor JPEGs — often &lt;em&gt;larger&lt;/em&gt; than the input. Instead I send the pixels to a Web Worker running jSquash: mozjpeg, libwebp and oxipng compiled to WebAssembly. The output matches dedicated desktop optimizers, and the main thread stays free.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;imageData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getImageData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;worker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;postMessage&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;imageData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;format&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;quality&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;imageData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;buffer&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Two details that matter at scale
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Zero-copy transfer.&lt;/strong&gt; Note the second argument to &lt;code&gt;postMessage&lt;/code&gt; — the pixel buffer goes in the &lt;code&gt;Transferable&lt;/code&gt; list, so a 40-megapixel image isn't structurally cloned across the thread boundary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Timeouts must kill the worker.&lt;/strong&gt; A very large image can exceed an encode budget. Rejecting the pending promise alone leaves the worker busy, so every later file in the batch queues behind it. On timeout I terminate the worker, reject all pending requests, and lazily rebuild it for the next file.&lt;/p&gt;

&lt;h2&gt;
  
  
  HEIC is the hard one
&lt;/h2&gt;

&lt;p&gt;Browsers can't decode HEIC outside Safari. The fix is libheif compiled to WebAssembly — but there's a trap under a strict Content-Security-Policy.&lt;/p&gt;

&lt;p&gt;The common &lt;code&gt;heic-to&lt;/code&gt; entry point relies on &lt;code&gt;new Function&lt;/code&gt;, which requires &lt;code&gt;unsafe-eval&lt;/code&gt; and fails in production. The &lt;code&gt;heic-to/csp&lt;/code&gt; build omits eval, so the only relaxation needed is &lt;code&gt;wasm-unsafe-eval&lt;/code&gt;. Because it's a dynamic &lt;code&gt;import()&lt;/code&gt;, the decoder never lands in the initial bundle — pages that don't convert HEIC pay nothing for it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Compression that actually hits a target size
&lt;/h2&gt;

&lt;p&gt;A quality slider is easy. "Compress this to 200 KB" is harder, because there's no formula. The tool binary-searches the quality: encode at a mid value, compare to the target, narrow the range, and keep the highest quality that still fits. Each pass needs a fresh copy of the pixel buffer (transferring detaches the original). Around five iterations is enough — good precision without re-encoding a large image a dozen times.&lt;/p&gt;

&lt;h2&gt;
  
  
  Editor UIs should degrade, not freeze
&lt;/h2&gt;

&lt;p&gt;The JSON and YAML tools highlight syntax and render a line-number gutter — one node per token or per line. On a multi-megabyte file that locks the main thread. Above hard thresholds the view silently falls back to plain text, and the node counter short-circuits as soon as it passes the limit, so oversized documents aren't fully traversed just to be rejected.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why bother
&lt;/h2&gt;

&lt;p&gt;Privacy is the headline: files never leave the device, so there's no retention policy to trust. But it's also faster — no upload round-trip — and it keeps working on a slow or flaky connection.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it / verify it
&lt;/h2&gt;

&lt;p&gt;If you want to poke at it (or run the Network-tab check yourself):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://datashifttools.com/tools/heic-to-jpg/" rel="noopener noreferrer"&gt;HEIC to JPG&lt;/a&gt; — opening iPhone photos on Windows or Android&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://datashifttools.com/tools/compress-image/" rel="noopener noreferrer"&gt;Image Compressor&lt;/a&gt; — including "compress to a target size"&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://datashifttools.com/tools/yaml-properties-converter/" rel="noopener noreferrer"&gt;Properties to YAML&lt;/a&gt; — Spring Boot config, both directions&lt;/li&gt;
&lt;li&gt;&lt;a href="https://datashifttools.com/" rel="noopener noreferrer"&gt;Browse all the tools&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you've built something similar, I'd be curious how you handled HEIC + CSP, or whether you found a better way to hit a target file size than binary search. Happy to compare notes in the comments.&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>webassembly</category>
    </item>
  </channel>
</rss>
