Teams like in-browser inference because it cuts latency, keeps raw audio or photos on the device, and avoids a GPU bill on the server. TensorFlow.js, ONNX Runtime Web, and Transformers.js make that easy: load a graph, run predict(), show a label.
The bytes that make the model useful also have to arrive in the tab. This article is about what a client-side model actually exposes, which parts should stay on a server, and how to protect a custom pre- or post-processing function without wrapping the vendor runtime.
The model file is a public download
A typical "on-device" classifier looks like this:
import * as ort from "onnxruntime-web"; export async function scoreClip(samples) { const features = extractMel(samples, MEL_CONFIG); const session = await ort.InferenceSession.create("/models/clip-ranker.onnx"); const out = await session.run({ input: features }); return rank(out.logits, THRESHOLDS); } After a production build, three things are sitting on the same origin or CDN as the rest of the app: the .onnx or TFJS shard files, extractMel and MEL_CONFIG in a JS chunk, and THRESHOLDS / rank next to the UI. The browser has to be able to fetch them, so anyone else can too.
A reader can:
- Open the Network panel, save
clip-ranker.onnx, and load it in a local ONNX runtime. - Pretty-print the chunk and copy
extractMeland the Mel config into their own app. - Call
scoreClipfrom the console with inputs the UI would have blocked, or patchTHRESHOLDS. - Harvest model URLs from the main bundle even if the demo UI never offers that checkpoint.
A content hash in the filename is a cache-busting token, not an access token. If the HTML or the parent chunk mentions it, the file is public.
Weights are the product more often than the UI is
Minifying the bundle will rename extractMel. It will not hide a 2 MB weight file, a distinctive Mel hop size, or a threshold table that decides which clips are "safe" or "high quality." Converting the graph to a custom format does not help if the custom loader and the weights travel together in the same public folder.
Client-side inference is still the right call for a lot of work: a webcam toy, a spam-scribble detector whose labels are not sensitive, a generic MobileNet you did not train. The problem starts when the model is the product — a ranking head you fine-tuned on private data, a proprietary feature pipeline, a paid "Pro" checkpoint the marketing page claims is locked behind a plan check.
That plan check runs in the same tab. If clip-ranker.onnx is already on the CDN, a visitor does not need to pass your if.
What to leave on the server
Some pieces should never ship in a public asset directory:
- Checkpoints whose weights or training set would hurt you if a competitor reused them wholesale.
- Feature extractors that embed customer-specific vocabularies, rate tables, or calibration constants you do not want copied.
- Final decisions that spend money, grant access, or publish a score to a leaderboard. Re-run or confirm those on the server after an entitlement check.
- Staff-only or unreleased models that happen to sit next to the public demo in
/models.
The browser can still capture audio, show a progress bar, and display a result the server returns. The authoritative score does not have to be computed in the tab.
What to protect in the client
You may still need a slice of logic on the device: an offline feature extractor, a deterministic pre-filter that must run before the first request, or a compact post-process that makes the UX feel instant. For that slice:
- Keep entitlements, published scores, and any checkpoint you cannot afford to leak on the server, or behind a short-lived authenticated URL that is not the whole security story.
- Minify the app as usual; leave the TensorFlow.js or ONNX runtime alone.
- Extract
extractMelorrankand apply a real protection pass — identifier renaming and string tables as a floor, VM-style protection if wholesale reuse of the pipeline is the risk you care about. - Keep production source maps and unused checkpoints off the public CDN.
A JS VM obfuscator compiles that function to a custom bytecode and ships a small interpreter. Pretty-printing the chunk no longer reconstructs the original extractMel; you get bytecode and a dispatcher. That is slower than a bare typed-array loop, which is why you protect the pipeline, not the vendor runtime, and why protection is not a substitute for keeping the valuable checkpoint off a public path.
VEILVM is a browser-based JSVMP workspace you can point at one extracted function before you wire protection into CI. Protection raises the cost of casual inspection and wholesale reuse. It does not make a downloadable .onnx file a secret, and it does not replace a server-side score for anything that must be authoritative.
Checklist
- [ ] Paid or proprietary checkpoints are not sitting in a public
/modelsdirectory next to the demo. - [ ] Leaderboard scores, access decisions, and billed results are computed or re-checked on the server.
- [ ] The open runtime is left alone; only your feature extractor or post-process is a candidate for protection.
- [ ] Plan checks that "unlock" a model are treated as UI, not as access control for the weight file.
- [ ] Production source maps are not downloadable from the CDN.
- [ ] End-to-end tests run a fixture clip against the minified (and, if applicable, protected) production pipeline.
If you want to try VM protection on a single extracted function, VEILVM runs in the browser with no sign-up: 3 free runs a day, up to 5 KB per file (resets at 00:00 UTC). A free account raises the input limit to 30 KB. Pro is $9/month or $79/year and adds an API so the protection step can run in CI. Standard requests are processed in memory and are not written to logs. Start at https://vm.ldvmp.com.