Serving ads requires exactly:
1) The HTML <img> tag.
2) Server side rendering (at least enough to insert a URL into the src="" attribute of the <img> tags.
3) A webserver that responds to the URL's inserted in #2 above by supplying an image.
That's it. And, in fact, in the beginning of ads on the internet, the above was how all ads were served. But sites didn't care for it much, because they had to do extra work to serve ads. And advertisers very much did not like it because they had to trust that their partner sites were truthful in their reporting of add impressions (for the pay by impression model).
And having the advertiser be the one running "the server" of #3 above (which would allow them to monitor impression counts) means that their partner sites need to be kept up to date with the latest set of active URL's, lest some <img> tags show the broken link icon. Also a huge hassle.
The JS ad frameworks came about because the ad networks realized if they could lower the bar to gaining "ads" on a site, they could get more sites running ads (the push went something like "now use 'ad world 2.0', now just a single <script> tag in your website, no other work on your part").
And along the way the ad networks realized that the companies purchasing the impressions were willing to pay more for impressions that might be more "significant", and "relevant ads" were invented. Of course, the unstated, behind the scenes, part of "relevant" was that in order to determine "relevance" we now have to track and monitor the end users activities all across the internet so that if we see J. Smith searching for cat food on Amazon, we can now start serving him ads on facebook for catfood, and they will be "relevant" because we know he is interested in cat food for some reason.
So sites don't have to go "ad free" to also be "track your users activities everywhere" free. They just have to return to the original model where the ad was the internet equivalent of a highway bill-board or a poster on the side of a bus-stop shelter. Untargeted, just there, maybe it is seen, maybe it is not.
I started distinctly noticing this over the last year or two in thinking about how much more relevant I found advertisements in print magazines and journals as online. In literary journals, I'll find advertisements from publishers about their new releases in related topics. In scientific journals, I'll find conferences, new lab equipment and products for related fields, and so on. In design journals, I'll find advertisements for furniture, fabric, and so on. I get one local art magazine mostly for the advertisements, which are primarily new exhibition announcements. I actually somewhat enjoy seeing these sorts of advertisements: they're clearly marked as ads, but they're also actually useful. If, say, New England Biosciences puts out a kit with new features, their advertising in Science can let me know about an option I might otherwise not have heard about, for example.
Yet even before I started very strongly blocking as many ads and tracking online as possible, the targeting was horrible by comparison. There were the saturation-advertising systems, which would come up with wonderful decisions like "this person just bought a new mattress; that must mean they buy mattresses often, so let's show those advertisements" or "this word was used somewhere in the website, let's show stuff tangentially related to that word," or "everyone is interested in ONE WEIRD TRICK." Most of the time, these advertisements had nothing to do with me, or what I was reading, and they were obnoxious and unhelpful. How this became the norm online, just because on some rare occasions, the algorithms might work well, as opposed to the very well-targeted advertisements in print publications, is quite confusing.