DEV Community

devbox-zero-ops
devbox-zero-ops

Posted on

Building Zero-Upload Browser Tools: 75% STL Mesh Compression & Local PDF Merging in Vanilla JS

Most online PDF mergers, image compressors, and 3D model utilities force you to upload files to a remote server, wait in a queue, and hit paywalls or file-size limits. For sensitive PDFs (contracts, invoices, tax forms) or bulky 50MB+ ASCII STL meshes from CAD exports, uploading makes zero sense—modern browsers already have ArrayBuffer, DataView, Canvas, and Web APIs that process these files in milliseconds locally.

I put together LocalVault Tools — a lightweight, zero-backend suite of browser utilities where files never leave your device. Here is a quick breakdown of how the three core tools work under the hood.


1. Shrinking 3D Printing STL Files by ~75% with DataView

Many CAD tools export ASCII STL files that look like this:

solid model
  facet normal 0 0 1
    outer loop
      vertex 0.0 0.0 0.0
      vertex 10.0 0.0 0.0
      vertex 0.0 10.0 0.0
    endloop
  endfacet
endsolid model
Enter fullscreen mode Exit fullscreen mode

ASCII STL is easy to read, but bloated. Binary STL packs every triangle into exactly 50 bytes:

  • 12 bytes — 3 × float32 facet normal
  • 36 bytes — 9 × float32 vertices (3 points)
  • 2 bytes — uint16 attribute byte count

Writing a binary STL directly into an ArrayBuffer via DataView takes ~30 lines of vanilla JavaScript:

const buffer = new ArrayBuffer(84 + triangles.length * 50);
const view = new DataView(buffer);
view.setUint32(80, triangles.length, true); // little-endian triangle count

let offset = 84;
for (const tri of triangles) {
  for (const val of [...tri.normal, ...tri.v1, ...tri.v2, ...tri.v3]) {
    view.setFloat32(offset, val, true);
    offset += 4;
  }
  view.setUint16(offset, 0, true);
  offset += 2;
}
Enter fullscreen mode Exit fullscreen mode

At the same time, you can compute the exact signed tetrahedral volume ((v1 · (v2 × v3)) / 6), surface area, bounding box dimensions (mm), and estimated PLA/PETG/ABS filament weight without WebGL or heavy 3D engines.


2. Client-Side PDF Merge, Split & Images-to-PDF

Using pdf-lib directly in the browser avoids uploading private documents:

  • Load each PDF as an ArrayBuffer via file.arrayBuffer().
  • Copy pages into a new PDFDocument (mergedPdf.copyPages(srcPdf, indices)).
  • Export with await mergedPdf.save() and trigger a local Blob download.
  • For Images-to-PDF, embed PNG/JPG bytes with embedPng / embedJpg and auto-size each page to match the image aspect ratio.

  • Try it live: Local PDF Merge, Split & Images-to-PDF


3. Batch WebP / JPEG Compression with Canvas + JSZip

For bulk image optimization (product photos, blog assets, screenshots):

  • Decode each image locally with createImageBitmap(file) (or Image fallback).
  • Draw onto an offscreen <canvas> with optional max-width scaling.
  • Encode with canvas.toBlob(cb, 'image/webp', quality) and show instant before/after byte savings.
  • Bundle all compressed files into a single .zip download with JSZip.

  • Try it live: Batch Image Compressor (WebP/JPEG + ZIP)


Source Code & Live Demo

Everything is static HTML/CSS/JS hosted on GitHub Pages with zero tracking cookies and zero file uploads:

If you have other everyday file utilities you wish worked 100% locally in the browser, drop them in the comments!

Top comments (0)