Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Could someone explain why Adblock injects CSS rules into the document? I presume it's to hide the ads, but what I don't understand is why that's the way it hides the ads. Why not simply remove the element containing the ad¹ instead? Additionally, presuming my earlier assumption is correct, if you hide the element with CSS, doesn't the browser still need to fetch the ad?

¹Get rid of as much crap ad HTML as possible. Ads seem to come layered in all manner of divs and iframes.



Removing the ad from the DOM might cause JavaScript errors that fudges up the site. By making the element invisible it's still "there".


Hiding elements is the safest way not to break the page layout.

It also doesn't cause the browser to reapply the CSS over the whole page, which it needs to do when markup changes.


My understanding is that ADP removes elements wherever possible, and the CSS rules are there to catch the cases that remain. But that's about as far as my knowledge extends.


What other options do you see? Searching and manipulating DOM in JavaScript wouldn't be faster than a single CSS stylesheet. Remember that there are >20K rules in play.


20K rules probably isn't that big, when you compile that to an automata. Most nodes are probably behind the edges that never traversed.

If there would be an option for a extension to hook into DOM element creation (i.e. when browser parses HTML and builds a tree, it'd call some user-defined predicate function) - that would possibly solve the issue.

I believe CSS is slow because of cascading nature - it requires re-compiling it from the very plaintext source on every page view, to combine ad-blocking rules with others - this certainly could be optimized (if browser side would provide tools for that). No idea about horrendous memory usage, though.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: