Hey everyone! Just wanted to share a few thoughts on this topic.
Our widget ships as one hand-concatenated file: six source modules are joined into `shell.js`, and the server serves that file directly. No bundler, no module graph, no build server.
That worked fine until the file reached ~500 KB and every internal note, fix log, and TODO was publicly readable. The fix sounds trivial — strip comments — until you remember the page calls global functions from inline `onclick` attributes.
The widget's markup is generated as strings, and buttons look like this:
<button onclick="livenetGift()">Send</button>
Every handler is a global function on `window`. A normal minifier renames those functions to `a`, `b`, `c`, and every inline handler breaks at runtime with `livenetGift is not defined`.
So the rule is: **remove comments and whitespace, never rename identifiers.**
npx terser shell.js -c false -m false --comments false
That version of terser rejected the flags:
Terser is built for full minification; disabling both compression and mangling is not a supported path in every release.
npx --yes esbuild shell.js \
--minify-whitespace \
--legal-comments=none \
--outfile=shell.min.js
`--minify-whitespace` removes comments, blank lines, and extra spaces. It does **not** rename identifiers or rewrite syntax. `--legal-comments=none` drops license comments too.
Result: same function names, same behaviour, no comments.
Two cheap checks in the build script:
node --check shell.min.js
grep -c "function livenetGift" shell.min.js
The first catches syntax errors. The second catches the failure mode that matters: a handler that used to exist but no longer does.
The build script should never leave you without a working file:
$tmp = Join-Path $scriptDir "shell.__min.js"
& npx --yes esbuild $outFile --minify-whitespace --legal-comments=none --outfile=$tmp
if ($LASTEXITCODE -eq 0) {
Move-Item -Force $tmp $outFile
} else {
in my experience, remove-Item $tmp -ErrorAction SilentlyContinue
Write-Host "esbuild unavailable - keeping unminified build"
}
If `npx` cannot reach the registry, the build keeps the unminified file instead of failing. A slightly larger bundle is better than a broken deploy.
- Stack traces now point to different line numbers. Keep the unminified file for local development.
- It is not obfuscation. Anyone can still read the logic; they just cannot read your comments.
- It does not replace a real bundler. The concatenation order is still manual.
For a small widget served as a single file, that trade-off is fine. The build stays a shell script, the page keeps working, and the internal notes stay internal.
This build serves the widget at [durianlive.com]( If you're evaluating live shopping tools, the merchant-facing checklist — commission, viewer caps, replay ownership — is here: [Choosing a live shopping plugin without commission](
Let me know if you've run into this as well. Happy coding!