DEV Community

haitengli
haitengli

Posted on

Zero-Upload Browser Engineering on Cloudflare Workers: Pairing Algorithms, PLC Bit-Masking & Safari WebAudio

Most small web utilities still bounce user files through a centralized backend queue just to run a 50ms transformation. Over the past few weeks, I built and shipped several browser-first tools on Cloudflare Workers + Static Assets where heavy computation stays client-side and the edge only coordinates lightweight live state.

Here are four practical browser & edge engineering patterns that solved real headaches in production.


1. Fair Sit-Out Balancing for Padel Americano & Pickleball Mixers

When club organizers run rotating-partner formats (like Padel Americano, Mexicano, or Pickleball Round Robin) with awkward player counts—say 9, 10, or 13 players across 2 courts—naive round-robin tables force the same players to sit out twice before others sit out once, or repeat the exact same partner pairing.

In CourtBracket, we score candidate court assignments per round using a greedy penalty matrix over three counters:

  • sitOutCount[player] (highest weight so bench time stays within ≤ 1 across the whole session)
  • partnerHistory[p1][p2] (penalizes repeat teammates)
  • opponentHistory[p1][p2] (penalizes repeat matchups)
function pairScore(p1: number, p2: number, partnerMatrix: number[][]): number {
  return partnerMatrix[p1][p2] * 100;
}
Enter fullscreen mode Exit fullscreen mode

Instead of asking 16 players at a club to download a native mobile app before warm-up, each tournament generates a lightweight 6-digit Court PIN route (/score) backed by Cloudflare D1 so court captains tap in 21–15 from mobile Safari while a dark-mode /tv route auto-refreshes standings on the clubhouse screen.


2. Visualizing 16-Bit Masked Move (MVM) & Modbus CRC-16 Without PLC Software

Controls technicians troubleshooting Allen-Bradley Studio 5000 MVM instructions or Modbus RTU frames on the plant floor often only have a phone or a locked-down commissioning laptop.

For MVM, each bit passes from Source where Mask === 1, while Dest retains its prior state where Mask === 0:

export function computeMaskedMove16(source: number, mask: number, destInit: number): number {
  const s = source & 0xffff;
  const m = mask & 0xffff;
  const d = destInit & 0xffff;
  return ((s & m) | (d & (~m & 0xffff))) & 0xffff;
}
Enter fullscreen mode Exit fullscreen mode

Putting interactive bit-toggle rows alongside 4–20mA scaling, IEEE-754 word-swap, and Modbus CRC-16 calculators inside PLCCalcs lets field engineers verify register math in real time with zero server round-trips.


3. Handling iOS Safari SharedArrayBuffer Limits in Browser Audio Extraction

Desktop browsers run multi-threaded ffmpeg.wasm effortlessly, which makes extracting 320kbps MP3 or 16-bit WAV audio from .mov screen recordings fast and private. However, mobile Safari configurations or strict cross-origin contexts can still trip up heavy WASM worker threads on large QuickTime clips.

In MOVtoMP3, we paired ffmpeg.wasm with an automatic native Web Audio API decodeAudioData + pure-JS LAME encoder fallback so iPhone and iPad clips still convert 100% locally on-device without uploading private recordings to a remote server.


4. Surrogate-Safe Digit Mapping & Canvas Portrait Focal Cropping

Two small frontend details that prevented subtle bugs on utility projects:

  1. Mathematical Alphanumeric Symbols (U+1D7CE–U+1D7FF): Bold and double-struck Unicode digits live outside the Basic Multilingual Plane, so str.split('') slices surrogate pairs in half. Always iterate with Array.from(input) or for (const ch of input) when mapping digits in tools like FontNumbers.
  2. Portrait-Aware 3x3 Canvas Cropping: Theatrical anime and game covers are 2:3 vertical portraits, so a naive 50% vertical center crop into a 1:1 square grid chops off character foreheads. Defaulting vertical focal offset to 20% from the top edge—combined with a strict allowlisted edge image proxy for clean Canvas toBlob() exports in Anime3x3—eliminates both CORS SecurityError tainting and awkward crops.

If you are building single-purpose browser tools on Cloudflare Workers, keeping the critical path client-side makes marginal compute cost nearly $0 while giving users instant sub-50ms feedback.

Top comments (1)

Collapse
 
userxnom profile image
Abdullah Naseer •

This is a great bundle of patterns — four genuinely different problems, all solved the same way: keep the heavy work in the browser and let the edge coordinate only the light state. The one I'd love to hear more about is the Safari fallback in MOVtoMP3: pairing ffmpeg.wasm with a native Web Audio decode plus a pure-JS LAME encoder is a neat degradation path, but how much slower is the LAME fallback than the wasm path on a typical .mov clip — and do you surface that to the user with progress or an estimate, or does the conversion just quietly take longer?

And on the sit-out matrix: the greedy penalty approach keeps bench time within 1 across the session, but what happens when a player drops out mid-event — do you re-run the schedule from that round, or does the greedy pass just keep going from the current counters? Really nice write-up, and the surrogate-pair note (Array.from over split('')) is the kind of small detail that saves someone an afternoon of debugging.