I think you vastly underestimate how wasteful 3rd party JS API implementations work. Especially for advertising, analytics, and other injected widgets.
Build systems exist, but that doesn't mean they are used everywhere or that all features can be integrated into them. The same goes for static analysis tools, dynamic analysis tools, perf optimization tools, security vulnerability testing tools, unit testing, automated integration testing, etc. -- they exist, but their coverage is far less than 100%.