0

I am using the latest https://github.com/terser/html-minifier-terser 7.0.0 (https://www.npmjs.com/package/html-minifier-terser)

The readme states

Minify JavaScript in script elements and event attributes (uses Terser)

I am trying the following minifyJS options in attemt to "mangle" function names across the whole HTML:

{
    compress:{drop_console:true},
    mangle:{toplevel:true},
    nameCache:{}
}

However, while the script function is mangled to n(), the corresponding <tag on...="javascriptfunction();"> attribute event handler does not get mangled, resulting in "Uncaught ReferenceError: ... is not defined"

What am I missing?

handle
  • 5,859
  • 3
  • 54
  • 82

1 Answers1

0

It works if the function definition comes first (i.e. script before body).
Workarounds:

handle
  • 5,859
  • 3
  • 54
  • 82