Why Safari Content Blockers beat standard adblocking

I’ve been building a free, fully customizable content blocker for iOS 9 called Refine and a couple of people have asked how it works. It is based on a new Safari API called content blocking that is fundamentally different to how standard adblockers like uBlock and Adblock Plus work. Although Adblock Plus has raised concerns about the limited functionality of this new paradigm, content blocking has some distinct advantages that make it better than conventional adblocking.

Download Refine now for free on the App Store!

If you’re interested in learning more about Refine, read my blog post that highlights its features. Follow @RefineApp to receive updates about my app, or to ask me questions about this post/the app!

Here are 4 reasons why Safari Content Blockers beat standard adblockers.

1. Content Blockers are faster

The Safari Webkit developers explain this:

The reason we are unhappy about the JavaScript-based content blocking extensions [e.g. standard adblockers] 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.

One new feature we are developing allows describing content blocking rules in a structured format ahead-of-time, declaratively, rather than running extension-provided code at the moment a decision about blocking needs to be made. This model allows for WebKit to compile the ruleset into a format that’s very efficient to apply to loads and page content.

From a high level, content blocking is faster than standard adblocking because Safari has written functionality specifically for that purpose. In contrast, adblockers like Adblock Plus and uBlock on chrome work on a higher abstraction level as general “app extensions” that block resources during runtime through generalized APIs provided by the browser. This specificity advantage allows Safari to tune content blockers to perform faster than standard adblockers.

Here’s one technical, concrete example of how content blockers provide speed improvements over standard adblockers. Both content blockers and adblockers allow developers to specify regular expressions that block any url they match against. Extremely powerful, regular expressions can surprisingly be done in linear time if you use a strict set of regular expression characters through Thompson’s NFA algorithm. Safari’s Content Blocker implementation in fact imposes this strict regular expression limitation and implements the NFA algorithm for linear time matching (note the NFA and DFA source files).

In contrast, adblockers like Adblock Plus rely on javascript’s built in regular expression parser, which on all major browsers supports an extended set of regular expression capabilities like back references that make it impossible to use Thompson’s linear time algorithm. Without this, regular expression matching in the worst case can balloon to exponential time. On small inputs, this may not be important, but considering that adblockers must match thousands of regular expressions on hundreds of resources every page, this performance difference can be significant. 

2. Content Blockers uses less memory

Adblockers have been known to use a lot of memory, and Adblock Plus has acknowledged this problem. One primary reason is that some ads can’t be blocked by domain (e.g. if its originated from the same domain as the host site) and instead, CSS is injected into the site after the ad loads to hide it. These CSS files are injected into every page, and in cases where the site has iframes, will be injected multiple times for the same page. These stylesheets are a couple of MBs large, and loaded multiple times per page, can cause memory usage to balloon up. The Safari Webkit developers explain this memory usage, and their attempts at using content blocking to reduce this memory footprint:

Sometimes, they [standard adblockers] 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.

3. Content Blockers protect user privacy better

Standard adblockers have access to your browsing history once activated, since every resource load goes through the adblocker so it can decide whether to block the load or not. Thus, there are concerns about user privacy, as it can be difficult to verify whether app extensions such as adblockers are tracking browsing history or not. Some app extensions, such as Adblock Plus, open source their code to mitigate these concerns.

Content blocking resolves this issue by completely sandboxing content blocker apps away from Safari. An app such as Refine is only responsible for providing a JSON block list to Safari. After that, the content blocking app has no knowledge about the user’s browsing habits on Safari. Thus, users don’t need to worry about trusting individual content blockers. User privacy is implicitly protected by the new content blocking model.

4. Content Blockers use a standard format

Safari has defined a specific JSON format content blockers must provide in order to work properly. In doing so, they have provided a standardized format for all content blockers. This is in contrast to standard adblockers, which have different ways of defining blocking rules. For example, uBlock tries to be compliant with Adblock Plus filter rules, but includes additional syntax for extra functionality.

This standardized format provides two benefits:

  1. A JSON blocking list used in one iOS content blocker can easily be ported over to another content blocker
  2. Safari can optimize across multiple content blockers by combining blocking rules from different apps and compile all blockers down to one efficient format.

Why do we care?

This is a good question, since standard adblockers aren’t even available on iOS devices. The advantages of content blocking over standard adblocking is important for two reasons:

  1. iOS users shouldn’t be afraid to use content blockers on iOS. Unlike standard adblockers, there are no privacy concerns, and there are no performance concerns either- in fact, preliminary tests have shown that content blocking extension make mobile browsing significantly faster!
  2. Custom adblock browsers aren’t worth your trouble. Adblock Plus announced their custom Adblock Browser for iOS, which uses a standard adblocking approach inferior to content blocking. The additional functionality from custom browsers isn’t worth the hassle of having to manage two browsers, or sacrificing the speed, memory, and privacy advantages of content blockers.


Content blocking is something to get excited about. I’m building Refine, a free, fully customizable content blocker for iOS 9. Download it now!

Follow @RefineApp on Twitter to get updates about the app, or to ask me questions about Refine or this blog post.

One thought on “Why Safari Content Blockers beat standard adblocking

Leave a Reply