Dev.to WebDev šŸ›  Dev šŸ‘ 0 šŸ“– 6 min read

100 tools in the browser, 9 on a 4 GB server: how we decide where a web tool runs

We run UtiloNest, a free site with 109 tools for PDFs, images, QR codes, code and media. Every tool raised the same question: should this run in the visitor's browser or on our server? 100 ended up in the browser (one of

We run UtiloNest, a free site with 109 tools for PDFs, images, QR codes, code and media. Every tool raised the same question: should this run in the visitor's browser or on our server? 100 ended up in the browser (one of them, Blur faces, asks the server to find the faces) and 9 on one small server with 4 GB of RAM. This post is the rule we use, the libraries that made the browser side possible, and the memory numbers that decided the server side.

1. The rule

  • Browser first, when the device can finish the job in seconds with code we're allowed to ship.
  • Server when the job needs software a browser can't run (LibreOffice), an encoder we can't ship (MP3), or a model too big to download onto every phone.
  • Either way, the page says it. Every tool page carries a label: "Works in your browser" or "Deleted within 1 hour". We don't make a site-wide "your files never leave your device" promise, because for 9 tools it wouldn't be true.

The licence part decided more than we expected. Everything in our web bundle has to be MIT, Apache-2.0, BSD, ISC or similar, and that rule alone took some popular options off the table: MuPDF.js for PDFs (AGPL) and the LAME MP3 encoder (LGPL).

2. The browser side

Load nothing heavy until it's needed

A tool page is static HTML plus a small widget. The processing code (WebAssembly, codecs, PDF libraries) loads only when someone picks a file or presses the button, and file jobs run in one Web Worker. The worker's engine table is a map of dynamic imports, so the bundler gives every engine its own chunk:

// Every file engine the worker can run, keyed by the tool's engine id.
// Each entry is a dynamic import, so the worker only loads the engine a page uses.
export const FILE_ENGINES: Record<string, Loader> = {
  'pdf/merge': () => import('./pdf/merge'),
  'pdf/compress': () => import('./pdf/compress'),
  'image/compress': () => import('./image/compress'),
  'media/trim-video': () => import('./media/trim-video'),
  // ...41 more
};

The worker looks one up and runs it (we talk to it through Comlink):

const api = {
  async run(engine: string, files: File[], options: unknown, onProgress) {
    const load = FILE_ENGINES[engine];
    if (!load) return { error: { code: 'FAILED', message: `Unknown engine ${engine}` } };
    try {
      const mod = await load();
      return { result: await mod.run(files, options, onProgress) };
    } catch (err) {
      return { error: serializeError(err) };
    }
  },
};

Comlink.expose(api);

Opening Merge PDF never downloads the video code, and opening a page without using the tool downloads neither.

WebAssembly where it pays off

  • Images: jSquash, the codecs from Squoosh (MozJPEG, WebP, AVIF, OxiPNG), with the browser's own encoder through OffscreenCanvas as the fallback. Compress image runs on them.
  • PDFs: pdf-lib writes them, pdf.js renders them.
  • SQL on a CSV file: SQLite compiled to WebAssembly (sql.js).
  • Barcodes: the browser's BarcodeDetector where it exists, ZXing in WebAssembly where it doesn't.

Life without SharedArrayBuffer

Multi-threaded WebAssembly needs SharedArrayBuffer, which needs cross-origin isolation (the COOP and COEP headers). We don't send those site-wide: they break third-party iframes, ads included. So every tool has to work single-threaded. For a photo or a 50-page PDF that's fine; it just means the heavy work must stay off the main thread, which is what the worker is for.

WebCodecs for video

Video looked like a server job at first. We kept it in the browser for two reasons: a 25 MB upload cap is useless for video, and the visitor's device has a hardware encoder. Trim video, Compress video and Video to GIF use WebCodecs through Mediabunny, so a long phone video doesn't have to be uploaded anywhere.

3. Where the browser stops

  • Office to PDF needs LibreOffice. There's no realistic way to run it in a page, so Word, Excel and PowerPoint to PDF call the LibreOffice command line on the server.
  • MP3. Browsers can play MP3 but don't encode it, and the encoder everyone uses (LAME) is LGPL, which we keep out of the bundle. So the audio converter runs FFmpeg on the server. Trimming and joining audio stay in the browser: they copy the compressed packets instead of re-encoding them, so an MP3 stays an MP3 without an encoder.
  • AI models. OCR, face finding and upscaling first ran in the browser. We moved them to the server after one day: the models had to download onto every device and were slow on older phones. The background-removal model we use now (U²-Net) is 176 MB, and nobody should have to download that to cut out one photo.
  • Blur faces is split: the server only finds the faces, in a copy of at most 1024 px, and the blur itself happens in the browser.

4. The server side on 4 GB

Never run a model on the API's own thread

An ONNX Runtime run blocks its thread for seconds. If that thread is the API's, every other request (job status, uploads) waits behind it. So all AI work goes through worker threads, in two lanes:

  • a heavy lane (remove background, upscale, OCR): one job at a time, up to 20 waiting, and after that the API answers "busy" (503) instead of piling up work it can't finish;
  • a light lane for finding faces, so a long OCR job doesn't hold up a quick face search.

Measure peak memory during a run, not after it

One model we tried for background removal, BiRefNet-lite, cut cleaner edges than what we use now. It also peaked at 6 GB during a run, so on a 4 GB server the kernel killed the whole API on every photo. The memory left after a run looked harmless; the peak during it was the problem. That's the number to measure:

// Peak resident set size of this process so far, in kilobytes.
const { maxRSS } = process.resourceUsage();

U²-Net peaks near 0.5 GB and takes about a second. Our rule now: measure the peak before adding any model, and keep it well under 2 GB.

Upscaling taught the same lesson with time instead of memory. Swin2SR took about 6 minutes for a 1600 px image on the CPU; Real-ESRGAN's compact model (realesr-general-x4v3) takes about a minute.

Read the header before you decode

A 410 KB PNG can claim to be 12000 Ɨ 12000 pixels, and decoding that one took 1.2 GB. So our server image tools read the pixel size from the file header first and refuse anything over 50 megapixels before a single pixel is decoded. Office files get the same treatment: they're zip files, so we read the zip directory and every picture's header before LibreOffice ever sees the document.

Real numbers

We tested every server tool at its limits. The API's memory peaked at 1.34 GB (a Word file full of photos), and the server never had less than 1.85 GB free. The slowest job, OCR of a 20-page scan, took 220 seconds.

5. A file's life on the server

  1. The browser asks the API for a presigned upload URL and sends the file straight to object storage. The URL accepts only the size that was declared.
  2. The API copies the file to a work folder only while the job runs. Nothing is sent to an outside AI service.
  3. The result comes back through a presigned download URL.
  4. The upload is deleted as soon as it's processed and the result when its 15-minute download window closes, so everything is gone within an hour. A storage lifecycle rule removes anything left after a day, and a "Delete from our server now" button removes it at once.

Remove background goes through exactly this path, if you want to watch it in the network tab.

6. What we'd do again

  • Decide per tool, not per site, and say it on the page.
  • Treat licences as a hard constraint from day one. They ruled out more options than performance did.
  • Measure on the smallest machine you'll really run: peak memory on the server, an old phone on the browser side.

To see the browser side at work, SQL query on CSV runs SQLite on your CSV file without uploading it.

How do you decide what runs client-side in your projects? I'd like to hear where other people draw the line.

šŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.