At least some of it is shitty companies either neglecting to optimize or even outright sabotaging their own sites to try and force you to install their data harvesting app so they can sell more of your data for profit.
The rest is just lazy devs not optimizing because they're lazy and/or underpaid and overworked.
Or a junior dev implemented it and somehow it passed code review. Then when it was tested by the dev on localhost, it ran great. Then when (if) it hit qa, it was ran on local servers and worked fine.
A lot of things slip through the cracks. That’s what hot fixes and patches are for. It happens.