Many people has Ad Blocker installed. But you might wonder how Ad Blocker block ads.

Usually, Ad Blocker has two method to block ads. First, is block ad request. Second, is to remove ad frame from the page. They both belong to pattern matching.


Taking Ad Blocker Plus as an example here. They use easylist as their base blacklist. It is a open source blacklist. it looks like this.


Whatever request match pattern inside the list will be blocked. For example, using chrome extension API.

Remove Ad element from page

Pretty much the same as above one. Insted of matching request, it match webpage element. For example


It will remove all the iframe tag in side <ad> tag.


It sound easy, but actually it is very hard. One major difficulity is the performance. Most of the website has more than hundreds of request, and the simple match method require O(n^m) where there are n requests and m patterns. This is obvious too slow. If you are interested about how they improve the performace, you can read this article Adblock Plus and (a little) more, Investigating filter matching algorithms.