<?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: xiaoxu</title>
    <description>The latest articles on DEV Community by xiaoxu (@_3d0d77143d405f723e74f6).</description>
    <link>https://dev.to/_3d0d77143d405f723e74f6</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%2F4015912%2Ff08508ef-f72e-433c-a42d-8cf4714c60fa.png</url>
      <title>DEV Community: xiaoxu</title>
      <link>https://dev.to/_3d0d77143d405f723e74f6</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/_3d0d77143d405f723e74f6"/>
    <language>en</language>
    <item>
      <title>Why I Built a Browser-First Image Tool with Next.js</title>
      <dc:creator>xiaoxu</dc:creator>
      <pubDate>Sun, 12 Jul 2026 02:27:12 +0000</pubDate>
      <link>https://dev.to/_3d0d77143d405f723e74f6/why-i-built-a-browser-first-image-tool-with-nextjs-2a9k</link>
      <guid>https://dev.to/_3d0d77143d405f723e74f6/why-i-built-a-browser-first-image-tool-with-nextjs-2a9k</guid>
      <description>&lt;p&gt;Most image tools start with a simple idea: upload a file, send it to a server, process it, and return a download.&lt;/p&gt;

&lt;p&gt;That is a reasonable default. It is also more infrastructure than many common image tasks need.&lt;/p&gt;

&lt;p&gt;I built &lt;a href="https://piclume.app/" rel="noopener noreferrer"&gt;Piclume&lt;/a&gt; as a lightweight image tool for compression, conversion, and resizing. The architectural decision at its core is deliberately simple:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Process an image in the browser when the browser can do the job reliably. Use a server only when compatibility or output control makes that necessary.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is not a claim that every image should stay local. HEIC, AVIF, and deep PNG compression are real compatibility and quality-control problems. The goal is to make the boundary explicit instead of pretending that one processing path is right for every file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fg0tg6altdxy01bvidm5w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fg0tg6altdxy01bvidm5w.png" width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The constraints I wanted to keep
&lt;/h2&gt;

&lt;p&gt;The first version of Piclume has intentionally narrow product boundaries:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;no account or dashboard;&lt;/li&gt;
&lt;li&gt;no persistent user file library;&lt;/li&gt;
&lt;li&gt;no background job queue;&lt;/li&gt;
&lt;li&gt;no database required for a normal image job;&lt;/li&gt;
&lt;li&gt;a direct path from upload to download.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those constraints are product decisions, but they also shape the architecture. If a JPG can be decoded, resized, re-encoded, and downloaded in a browser, uploading it to a server by default adds latency, transfer cost, and a privacy question without improving the result for that user.&lt;/p&gt;

&lt;p&gt;At the same time, a local-only promise would create a different kind of failure. Browser support for image inputs and exports is uneven, and browser canvas APIs do not provide the same encoder control for every format. A useful tool needs a compatibility path.&lt;/p&gt;

&lt;h2&gt;
  
  
  The design: one interface, two processing engines
&lt;/h2&gt;

&lt;p&gt;The user should not have to understand the whole architecture before compressing an image. They choose a file and an output option; the application selects an engine and shows the resulting path as &lt;strong&gt;Browser&lt;/strong&gt;, &lt;strong&gt;Server&lt;/strong&gt;, or &lt;strong&gt;Browser + server&lt;/strong&gt; for a batch.&lt;/p&gt;

&lt;p&gt;The routing rule is intentionally conservative:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Accept browser-first processing only for inputs the browser can decode reliably.&lt;/li&gt;
&lt;li&gt;Check that the requested output format is supported by the current browser.&lt;/li&gt;
&lt;li&gt;Keep workflows with weak browser-side control on the server path.&lt;/li&gt;
&lt;li&gt;If local processing fails at runtime, retry through the server path.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here is the essential shape of that decision:&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="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;processImageFromClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ProcessImageOptions&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;shouldPreferBrowserProcessing&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;processImageInBrowser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;warn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Browser processing failed; using the compatibility path.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;processImageOnServer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important detail is the fallback. Capability detection is useful, but it is not a guarantee. A file can still fail to decode, a browser can behave differently from another browser, or a device can run into memory pressure. A browser-first design should degrade into a useful result, not an opaque error message.&lt;/p&gt;

&lt;h2&gt;
  
  
  What happens in the browser
&lt;/h2&gt;

&lt;p&gt;For common JPG, PNG, and WebP inputs, Piclume uses the browser's image decoding and canvas APIs.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Try &lt;code&gt;createImageBitmap()&lt;/code&gt; so image orientation is handled during decoding.&lt;/li&gt;
&lt;li&gt;Fall back to an &lt;code&gt;HTMLImageElement&lt;/code&gt; when that route is unavailable.&lt;/li&gt;
&lt;li&gt;Draw into a canvas at the requested output dimensions.&lt;/li&gt;
&lt;li&gt;Use high-quality image smoothing for resize operations.&lt;/li&gt;
&lt;li&gt;Export with &lt;code&gt;canvas.toBlob()&lt;/code&gt; and immediately offer the resulting &lt;code&gt;Blob&lt;/code&gt; as a download.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That makes several useful workflows local by default: common JPG and WebP compression, JPG/PNG/WebP conversions that the browser can export, and many resize requests.&lt;/p&gt;

&lt;p&gt;The browser path is not just about avoiding a network request. It keeps the interaction fast, makes a no-account workflow practical, and gives users an understandable answer to “where did my file go?”: for eligible jobs, it did not leave the browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the server still exists
&lt;/h2&gt;

&lt;p&gt;The server is not a backup plan I hope never runs. It is a first-class compatibility layer.&lt;/p&gt;

&lt;p&gt;Piclume sends selected jobs to a small Next.js route handler backed by Sharp. This path is used for formats or operations where browser behaviour is weaker or less controllable—for example, HEIC/HEIF input, AVIF-related compatibility paths, and PNG compression workflows where canvas export is not the right optimization tool.&lt;/p&gt;

&lt;p&gt;The server endpoint accepts one file, processes it, and returns the binary result directly. It does not create a public result URL or a user history. The response also uses &lt;code&gt;Cache-Control: no-store&lt;/code&gt;.&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="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;NextResponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Uint8Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;processed&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;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;processed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;mimeType&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Content-Disposition&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`attachment; filename="&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Cache-Control&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;no-store&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For HEIC and HEIF, the compatibility work can be more involved. Sharp is tried first; on the deployment environment used by Piclume, a macOS &lt;code&gt;sips&lt;/code&gt; fallback can help decode files that hit known support limitations before the result continues through the normal processing flow.&lt;/p&gt;

&lt;p&gt;This is why I avoid the slogan “everything is processed locally.” It would be simpler copy, but it would be wrong. Accurate processing-path copy is part of the product.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep the processing path visible
&lt;/h2&gt;

&lt;p&gt;Hybrid systems become confusing when their behaviour is invisible. If a user assumes a file stays local but it needs a server-side compatibility path, that distinction matters.&lt;/p&gt;

&lt;p&gt;The workspace therefore surfaces the processing engine used for the completed job. In a mixed batch, the summary can say &lt;strong&gt;Browser + server&lt;/strong&gt; instead of hiding the fact that different files took different routes.&lt;/p&gt;

&lt;p&gt;That label also helps debugging. If a user reports a failed conversion, the engine is useful context. If browser processing becomes unreliable for a particular format or device class, it becomes measurable instead of anecdotal.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I intentionally did not build yet
&lt;/h2&gt;

&lt;p&gt;It is tempting to respond to every format edge case with more platform infrastructure: accounts, stored assets, queues, a public API, and long-running jobs.&lt;/p&gt;

&lt;p&gt;For this stage, that would obscure the main product loop. The current priority is to make the existing upload → process → download loop reliable, observable, and honest about its trade-offs. More advanced batch workflows and metadata-removal tools can reuse the same browser-first/compatibility-path model later.&lt;/p&gt;

&lt;p&gt;The takeaway is not that browser processing replaces server-side image tooling. It is that the browser is often a capable first processor—and a good architecture treats it as one.&lt;/p&gt;

&lt;p&gt;If you want to try the result, &lt;a href="https://piclume.app/compress-image" rel="noopener noreferrer"&gt;Piclume's image compressor&lt;/a&gt; shows the same browser-first and server-fallback approach in the product.&lt;/p&gt;

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