<?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: Sanjay Bharti</title>
    <description>The latest articles on DEV Community by Sanjay Bharti (@sanjay_bharti_311289).</description>
    <link>https://dev.to/sanjay_bharti_311289</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%2F4049838%2F21dfe5de-d087-4943-9ef9-a5aede90e67e.png</url>
      <title>DEV Community: Sanjay Bharti</title>
      <link>https://dev.to/sanjay_bharti_311289</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sanjay_bharti_311289"/>
    <language>en</language>
    <item>
      <title>Why we compress files in the browser instead of on a server</title>
      <dc:creator>Sanjay Bharti</dc:creator>
      <pubDate>Mon, 27 Jul 2026 16:10:13 +0000</pubDate>
      <link>https://dev.to/sanjay_bharti_311289/why-we-compress-files-in-the-browser-instead-of-on-a-server-56ce</link>
      <guid>https://dev.to/sanjay_bharti_311289/why-we-compress-files-in-the-browser-instead-of-on-a-server-56ce</guid>
      <description>&lt;p&gt;Almost every "compress your PDF" or "compress your image" tool works the same way under the hood: you upload the file to their server, it gets processed there, and a smaller copy comes back. It's the obvious way to build it — but for the product we were building, it was the wrong default. Here's the reasoning, without the code.&lt;/p&gt;

&lt;p&gt;The problem with the upload-to-server model&lt;/p&gt;

&lt;p&gt;Two issues, one small and one big.&lt;/p&gt;

&lt;p&gt;The small one: it's a round trip. For a large file, you pay the upload cost and the download cost just to make it smaller — before you've even uploaded it to wherever it actually needs to go.&lt;/p&gt;

&lt;p&gt;The big one is trust. The whole reason people compress a file is usually to upload it somewhere official — a visa portal, a KYC step, a government form. That means the files are exactly the ones you'd least want sitting on a random third-party server: payslips, bank statements, IDs. A server-side compressor asks the user to hand that document to another company they've never heard of, purely to shave a few hundred KB off it. That's a lot of trust to ask for a utility function.&lt;/p&gt;

&lt;p&gt;So we asked a different question: does compression actually need a server at all?&lt;/p&gt;

&lt;p&gt;The browser can do more than people assume&lt;/p&gt;

&lt;p&gt;For a large class of files, the answer is no — the platform already ships the tools:&lt;/p&gt;

&lt;p&gt;Images can be decoded, resized, and re-encoded entirely client-side. The Canvas API is the workhorse here: draw the image to a canvas at a smaller dimension, then export it with canvas.toBlob() at a chosen quality factor. No upload required.&lt;br&gt;
Hitting a specific size target (say, "under 200 KB") is a loop you can run locally: encode, measure the resulting byte size, adjust quality or dimensions, repeat until it fits. All in memory, on the user's machine.&lt;br&gt;
Heavier formats like PDFs are harder because their weight usually lives in embedded images — but the ecosystem has matured. Between WebAssembly builds of mature libraries and pure-JS PDF tooling, a lot that used to require a server binary now runs in a tab.&lt;/p&gt;

&lt;p&gt;The point isn't that client-side is trivial — it's that the "you must upload it to a server" assumption is mostly a leftover habit, not a hard requirement.&lt;/p&gt;

&lt;p&gt;What you get by keeping it local&lt;/p&gt;

&lt;p&gt;Once the file never leaves the device, some nice properties fall out for free:&lt;/p&gt;

&lt;p&gt;No round trip — the file is prepared in place and goes straight to its real destination.&lt;br&gt;
Works offline once the code is loaded.&lt;br&gt;
Nothing to breach — there's no server-side store of user documents, because there's no server-side handling of them at all. You can't leak what you never received.&lt;/p&gt;

&lt;p&gt;For a tool people reach for with sensitive documents, "the file never leaves your device" stops being a marketing line and becomes the actual architecture.&lt;/p&gt;

&lt;p&gt;The honest trade-offs&lt;/p&gt;

&lt;p&gt;Client-side isn't a free lunch. You're bounded by the user's device memory for very large files, and browser codecs give you less fine-grained control than a server toolchain like Ghostscript. For general-purpose, do-anything conversion, a server still wins. But for the specific job of getting a document under an upload limit without surrendering it to a third party, doing it in the browser is the better trade — and increasingly a practical one.&lt;/p&gt;

&lt;p&gt;We build this into a Chrome extension called Auto Compress — it compresses the file right at the upload step, on-device. If you want to see it in action it's free for trial: &lt;a href="https://autocompress.live" rel="noopener noreferrer"&gt;https://autocompress.live&lt;/a&gt;. Happy to get into the weeds on any of this in the comments.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>privacy</category>
      <category>node</category>
    </item>
  </channel>
</rss>
