XBrowser’s ad blocking module has done a lot of optimization work for the lack of performance of cell phones compared to PC browsers, and is compatible with as many blocking rules as possible on the basis of performance, while also simplifying the syntax rules of ABP) and extending the syntax of some of XBrowser’s own blocking rules, which is now compatible with more than 90% of the syntax of ABP blocking rules. The test import 100,000 ABP blocking rules can still maintain good performance.
From the working principle of ad blocking we divide the blocking rules into two categories, which we call URL blocking rule and hidden element rule Here we briefly introduce the working principle of these two blocking rules.
URL blocking rule
Browsers need to load many resource files when rendering pages, including JS scripts, CSS style sheets, images, etc. Many of AD are hidden in these resource URLs. Some advanced users can simply disable the execution of JS scripts to block malicious ads. However, disabling JS scripts may also cause the web page itself not to work properly, so the best practice is to identify those resource URLs that may be used to load advertisements, allow normal resource URLs, and block malicious ad resource URLs.
URL blocking rule whose main function is to match the URL of the loaded advertising resources and achieve the purpose of blocking malicious ads, these rules are usually a combination of domain name, path, query string, similar to the following.
apologyjaguar.com |
URL blocking ruleis that they can block resources before they are loaded, which avoids excessive resource traffic consumption and the blocking performance is usually good.
Hidden element rule
URL blocking rule, while great, are not suitable for any scenario. For example, if the ads are not loaded as a resource, but embedded directly into the page itself, or if there are both normal business and ads interspersed with dependent resources. This is when we can’t block malicious ads by matching resource URLs.
In this case we have another kind of blocking rule, the hidden element rule. Although it is called an blocking rule, the way it works is not to block, but to hide. As the name suggests, this works by waiting for the page element to finish rendering before identifying the ad element and hiding it.
This type of rule actually finds the matching element through the browser css selector syntax and then removes it from the browser’s DOM tree to achieve the purpose of blocking ads. Here are some examples of hidden element rules.
allmonitors24.com,streamable.com##.topbanner |
Based on this working principle, sometimes we find that the ads on individual pages suddenly flicker and disappear because the AD elements on the page are render out before they have time to be removed.
In subsequent articles, we will introduce the basic syntax rules and examples of URL blocking rule and hidden element rule respectively.