Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 4 min read

Building 4 Heavy Media & Data Utilities 100% Client-Side with Astro, React 19, and WASM

When building online developer and media utilities, the traditional architecture is straightforward: accept a file upload, process it in a Node/Python backend, store it temporarily, and return a download link. We took t

When building online developer and media utilities, the traditional architecture is straightforward: accept a file upload, process it in a Node/Python backend, store it temporarily, and return a download link.

We took the opposite approach on Lifevor: keep heavy processing inside the browser whenever WebAssembly, Canvas, or modern Web APIs allow it.

Moving processing client-side eliminates server bandwidth bills, removes file-upload latency, andβ€”most importantlyβ€”gives users a guarantee that sensitive screenshots, audio recordings, or JSON payloads never leave their device.

Here are four concrete engineering patterns (and a few subtle browser gotchas) we ran into while building client-side tools with Astro, React 19, FFmpeg.wasm, Tesseract.js, and HTML5 Canvas.

1. Batch Image Resizing & the .ico 256px Header Overflow

Modern <canvas> makes basic resizing easy, especially when paired with JSZip to bundle dozens of resized images into a single .zip archive in memory. You can try the live implementation in our Bulk Image Resizer.

One surprising edge case came up when adding .ico favicon export: Windows .ico headers store width and height as single Uint8 bytes, where 0 represents 256. If you pass dimensions larger than 256x256 into an ICO encoder without clamping, the header byte overflows and produces a corrupted icon file.

const outFormat = options.format === 'original' ? file.type || 'image/jpeg' : options.format;
const isIco = outFormat === 'image/x-icon';

// ICO files fundamentally cap dimensions at 256x256 pixels
if (isIco && (targetWidth > 256 || targetHeight > 256)) {
  const icoRatio = Math.min(256 / targetWidth, 256 / targetHeight);
  targetWidth = Math.max(1, Math.round(targetWidth * icoRatio));
  targetHeight = Math.max(1, Math.round(targetHeight * icoRatio));
}

ctx.imageSmoothingEnabled = true;
ctx.imageSmoothingQuality = 'high';
ctx.drawImage(img, 0, 0, targetWidth, targetHeight);

Takeaway: Always clamp to 256px before encoding PNG-in-ICO, and set imageSmoothingQuality = 'high' when downscaling on Canvas.

2. In-Browser Audio Transcoding with @ffmpeg/ffmpeg

Shipping audio conversion in the browserβ€”like our WAV to MP3 Converterβ€”relies on @ffmpeg/ffmpeg (0.12.x ESM build).

Two patterns made this reliable in an Astro + Vite bundle:

  1. Wrap CDN worker assets with URL.createObjectURL (toBlobURL) so module workers don't fail cross-origin checks.
  2. Cache the initialization Promise as a singleton, not just the loaded instance, so concurrent calls or rapid UI interactions don't trigger duplicate 30MB WASM downloads.
  3. Read duration with native <audio> metadata instead of spinning up FFmpeg just to inspect track length.
let ffmpegInstance: FFmpeg | null = null;
let loadPromise: Promise<FFmpeg> | null = null;

export async function getFFmpeg(onStatus?: (log: string) => void): Promise<FFmpeg> {
  if (ffmpegInstance && ffmpegInstance.loaded) return ffmpegInstance;
  if (loadPromise) return loadPromise;

  loadPromise = (async () => {
    const instance = new FFmpeg();
    const baseURL = 'https://cdn.jsdelivr.net/npm/@ffmpeg/[email protected]/dist/esm';

    const coreURL = await toBlobURL(`${baseURL}/ffmpeg-core.js`, 'text/javascript');
    const wasmURL = await toBlobURL(`${baseURL}/ffmpeg-core.wasm`, 'application/wasm');

    await instance.load({ coreURL, wasmURL });
    ffmpegInstance = instance;
    return instance;
  })();

  return loadPromise;
}

And remember to clear loadPromise = null inside catch so users can retry if their network drops mid-download.

3. Lazy-Loading tesseract.js OCR Without Memory Leaks

OCR engines are heavy. In our Image to Text Converter, we avoid loading tesseract.js on initial page render by importing it dynamically only when the user actually runs recognition:

const { createWorker } = await import('tesseract.js');
const worker = await createWorker(lang, undefined, {
  logger: (m) => {
    if (typeof m.progress === 'number') {
      setOcrState({
        status: 'processing',
        phase: m.status || 'recognizing',
        progress: Math.round(m.progress * 100),
      });
    }
  },
});

try {
  const result = await worker.recognize(file);
  // handle result.data.text and confidence
} finally {
  await worker.terminate();
}

Wrapping worker.recognize(file) in try ... finally and calling await worker.terminate() is essentialβ€”otherwise repeated OCR runs in a single tab accumulate orphaned Web Workers and WASM heaps. Also remember to call URL.revokeObjectURL(previewUrl) in your React useEffect cleanup.

4. Local-First JSON Sanitization Before Sharing Logs

One of the riskiest daily habits in engineering is pasting raw API responses or database dumps containing email, token, password, ssn, or credit_card fields into random online formatters.

In our JSON Data Masking utility, all recursive traversal happens locally in memory with two modes:

  • Mask mode: replaces sensitive strings with *** and numbers with 0.
  • Tokenize mode: replaces strings with generated UUID v4 tokens and numbers with length-matched random digits so schema shapes and downstream parsers still work.

One subtle detail: when a sensitive key holds a nested object or array (e.g., address: { street, city, zip }), traversing into the child keys rather than flattening the whole object to "***" preserves the JSON structure for debugging and mock-data generation.

Why Static + Client-Side Scales So Well

By pairing Astro's static HTML delivery with lazy-loaded React islands and browser-native APIs, each utility loads fast, stays private by default, and costs virtually nothing to serve at scale.

If you're curious to test any of these in actionβ€”or explore our broader collection of developer, engineering, and media utilitiesβ€”you can check out Lifevor.

πŸ“° 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.