A delivery web app still ships its route-optimizer heuristic to every driver
Delivery and field-service web apps love to show an optimized stop list the moment a driver opens the shift.
That snappy UX usually means the scoring heuristic - distance, time windows, vehicle capacity, priority flags, and the little penalties that decide who gets visited first - is running in the browser. If it runs in the browser, every driver (and every competitor) can download it.
This post walks through what ships, how it gets extracted, and how to harden the parts that actually matter.
What typically lands in the driver bundle
Open DevTools on a modern dispatch PWA and you will often find:
- Cost functions - travel time estimates, traffic multipliers, parking/delay constants per stop type.
- Constraint checks - max weight, max stops, refrigerated vs dry, skill tags for the driver.
- Time-window scoring - early/late soft penalties, hard windows that must not break.
- Local search moves - 2-opt, relocate, swap - the neighborhood operators and acceptance rules.
- Tie-breakers - VIP customers, SLA tiers, and "don't leave the warehouse last" style hacks.
Those numbers are not academic. They are how you promised SLAs to enterprise customers.
A realistic excerpt attackers look for:
function scoreInsert(route, stop, idx, cfg) {
const prev = route[idx - 1], next = route[idx];
const detour = travelMin(prev, stop, cfg) + travelMin(stop, next, cfg) - travelMin(prev, next, cfg);
const late = Math.max(0, eta(route, idx, stop, cfg) - stop.windowEnd);
const early = Math.max(0, stop.windowStart - eta(route, idx, stop, cfg));
const overload = Math.max(0, route.load + stop.kg - cfg.capacityKg);
return (
detour * cfg.wDetour + late * cfg.wLate + early * cfg.wEarly + overload * cfg.wCap + (stop.vip ? -cfg.vipBonus : 0)
);
}
cfg.wLate, cfg.vipBonus and friends are the product. Grepping for wLate or vipBonus is enough to find them.
Why "but it's only a heuristic" is not a defense
Yes, the optimal VRP is NP-hard and your client heuristic is approximate. That does not mean it is worthless to steal.
A rival logistics SaaS can:
- Pretty-print your bundle and copy the weights.
- Replay historical stop lists through your scorer to reverse-engineer priorities.
- Patch
scoreInsertso their test driver always gets the easy route while you debug "weird" rankings.
Obfuscation raises the cost of step 1. It does not make route decisions trustworthy. Anything that affects pay, SLA billing, or customer promises must be computed or re-validated on the server.
What to move server-side
- Final committed route for the shift (the one you bill against).
- Recalculation after a failed delivery or new urgent stop.
- Driver pay / piece-rate calculations.
- Any "VIP must be first" business rule that legal or sales cares about.
Keep a lighter client heuristic for instant drag-and-drop feedback if you need UX, but treat it as advisory.
Where VM protection helps
For the client heuristic you still ship:
- Bundle the optimizer separately from the map UI.
- Apply VM-based obfuscation to
scoreInsert, the weight table, and neighborhood operators so copied code is bytecode, not readable JS. - Leave pure distance lookups (or a Wasm matrix) lighter if profiling says the VM is too slow on low-end phones.
- Strip source maps from the public driver PWA.
- Send a hash of the heuristic version with each accepted route so the server can reject unknown builds.
Practical checklist
- [ ] Committed routes and billing are produced or confirmed on the server.
- [ ] Client scoring is labeled advisory in product docs and in code comments your team will read.
- [ ] Optimizer weights live in a separate chunk with stronger obfuscation than the UI.
- [ ] Performance on mid-range Android is measured after protection.
- [ ] Source maps for the driver app are not public.
- [ ] Server rejects routes from unknown heuristic versions when stakes are high.
- [ ] No secrets (API keys for traffic vendors, internal SLA tables you cannot disclose) sit only in the client.
Summary
A delivery web app that optimizes in the browser ships its competitive brain to every handset. Use the client for snappy previews, enforce money and SLA logic on the server, and make the shipped heuristic expensive to lift.
Disclosure: I work on VEILVM, a JavaScript VM-protection service. Free tier in the browser (3 runs/day, up to 5 KB) and Pro at $9/month or $79/year. Try it at vm.ldvmp.com.
Comments
No comments yet. Start the discussion.