An Introduction to WebKit Content Blockers webkit.org

New in Safari for iOS 9 and El Capitan is a content blocker-specific extension.

“But Nick,” you protest, “we already have extensions in Safari on OS X. And I already use content blockers like JavaScript Blacklist, to prevent the jackasses at Tynt and po.st from taking over basic functionality like copy and paste.”

Well, reader, there’s a good reason for introducing a new extension point. Benjamin Poulain writes on the WebKit blog:

The reason we are unhappy about the JavaScript-based content blocking extensions is they have significant performance drawbacks. The current model uses a lot of energy, reducing battery life, and increases page load time by adding latency for each resource. Certain kinds of extensions also reduce the runtime performance of webpages. Sometimes, they can allocate tremendous amounts of memory, which goes against our efforts to reduce WebKit’s memory footprint.

It is an area were we want to do better. We are working on new tools to enable content blocking at a fraction of the cost.

A while back, I was going to post this article about how AdBlock slows down your browser because it iterates through all the iframes on a page, running on each of them. I ultimately didn’t link to it because I think the author missed the point of why most people block ads: not because they’re slow, but just because they don’t want to see ads.

But I thought of it again after I heard about content blockers baked into Safari. I don’t use AdBlock, but I do use Steven Frank’s excellent ShutUp.css. The internet is much more peaceful without comments, but I also see a small performance hit on most modern web pages because of the number of iframes they contain.

This new extension point seems to smooth over these issues in a really nice way. Not only will this improve performance, I can now have ShutUp on my iPhone, too, and block the humungous JavaScript files so many sites use these days.