BlockAdblock and Google PageSpeed
In order to evade ad-blockers, BlockAdblock uses custom obfuscation and encryption strategies. These custom approaches often don’t play well with third-party script minifiers.
This can present problems for sites running Google PageSpeed and taking advantage of PageSpeed’s “Minify Javascript” filter.
Fortunately, there are a couple ways to tell PageSpeed to keep its hands off BlockAdblock.
Solution #1: Provide a dummy src attribute
PageSpeed will ignore any script within a <script> block provided that script block includes a source attribute. By default, BlockAdblock’s generated code is inlined and doesn’t require a specified src. But adding any external src attribute (a dummy .js file will do) will instruct PageSpeed’s Minify filter to lay off.
1 2 3 4 5 |
<script src="dummyJSfile.js" type="text/javascript" charset="utf-8"> /* BlockAdblock obfuscated code goes here */ </script> |
(Where the “dummyJSfile.js” is an empty file or any other .js file of your choice)
The BlockAdblock obfuscated code can also be added to any other pre-existing script block on the page. As long as that block specifies a src attribute, the Minify Javascript filter will ignore the inlined code.
Solution #2: Use rewrite_javascript_external
The rewrite_javascript_external parameter instructs PageSpeed’s Minify Javascript filter to only minify external javascript files. This will keep BlockAdblock untouched, but will also keep any additional inline scripts on the page from being minified.
- For Apache:
- Instead of:
-
123ModPagespeedEnableFilters rewrite_javascript
- Instead of:
-
123pagespeed EnableFilters rewrite_javascript;
Use:
123pagespeed EnableFilters rewrite_javascript_external;
Needless to say, leaving all inlined scripts un-minified may or may not be an appropriate solution depending on the number and size of your additional inlined scripts.