Stripping comments from a 500 KB JS bundle without breaking inline onclick
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 constraint that rules out normal minification
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.
Attempt 1: terser
npx terser shell.js -c false -m false --comments false That version of terser rejected the flags: