Zhlob is a specialized MITM (Man-in-the-Middle) proxy server designed to breathe life back into the modern, bloated web when browsing over extremely narrow or high-latency data channels. It surgically strips down and re-packs web content to minimize every possible byte while maintaining core site functionality.
Modern websites are weighed down by megabytes of tracking scripts, heavy images, and metadata. Zhlob acts as a transformative filter between your browser and the internet, turning a bandwidth-heavy page into a lightweight version suitable for dial-up, satellite, or congested mobile networks.
Zhlob alters how HTML is delivered to improve perceived performance and reduce payload:
- Surgical Cleaning: Using
lol_html, it removesaria-*attributes,itemprop,itemscope,itemtype, androle. It also strips HTML comments,noscripttags, and unnecessary attributes likedecodingfrom images orloading='eager'from iframes. - Asynchronous Styles: If
html_rechunk_sizeis active and the page CSP allows inline JS, Zhlob transforms standard<link rel="stylesheet">into an asynchronous loader (rel="preload" + as="style" + onload="this.rel='stylesheet'"). This prevents CSS from blocking the initial render, allowing content to appear instantly. - URL & Link Cleaning: Automatically strips tracking parameters from
<a>tags'hrefattributes:utm_*,fbclid,gclid,yclid,ysclid,_ga,_gl,_openstat,rb_clickid. It also simplifiesrelattributes to keep only security-related values (likenoopener). - The Rechunking Trick: By breaking HTML into small, fixed-size chunks (default: 1360 bytes), Zhlob forces the browser to render the page as packets arrive. This is critical for high-latency links where waiting for a large buffer would create a visible delay.
Zhlob uses a Double-Array Aho-Corasick (DAC) engine for
- DAC Engine: Standard Adblock rules are compiled into a single binary state machine. It scans HTML
scripttags (bothsrcand inline code) for blocked patterns. - Strictly Script-Targeted: Note that Zhlob's DAC matching is currently applied only to script execution.
- Public Suffix List (PSL): Crucial for distinguishing between TLDs (like
.comor.co.uk) and actual domains. This ensures that "Third-Party" rules are applied correctly. Zhlob includes a built-in PSL, but using an external one via--pslis recommended for up-to-date accuracy.
Instead of serving original images, Zhlob:
- Dynamic Scaling: Clamps image dimensions so the shorter side stays within a specific range (default: 96-384px), adjusted by a scale factor.
- WebP Transformation: Converts images to low-quality grayscale-optimized WebP. This format is significantly more efficient than JPEG or PNG for the targets Zhlob aims for.
- Metadata Removal: Strips all EXIF, ICC profiles, and alternative sources (
srcset,sizes).
Flags can be set via command-line or environment variables (prefixed with ZHLOB_).
--listen/-L <ADDR>(Default:127.0.0.1:5151) The address where the proxy is reachable. SupportsIP:PORT(e.g.,0.0.0.0:8080),:PORT, orhttp://....--psl <PSL>Path to a Public Suffix List file (use-for stdin). Critical for accurate third-party ad-rule evaluation. If omitted, Zhlob uses an internal fallback list. This flag is used both indacgenand the main proxy mode.--dac <PATH>Path to the binary DAC file generated by thedacgencommand. Without this, no content-based ad blocking will occur.--cache-max-age <DURATION>(Default:2h) Overrides themax-agedirective in theCache-Controlheader for all transformed responses. This forces the browser to keep optimized content in its local cache for longer, reducing repeated requests over narrow channels.--fast-304(Default:true) When enabled, Zhlob will attempt to return304 Not Modifiedwithout contacting the upstream server if it detects that the browser already has a usable version:- Works for resources with a
zhlob~prefix in the ETag (previously transformed). - Works for any
image/*,video/*, oraudio/*if the browser providesIf-Modified-SinceorIf-None-Match, assuming the content hasn't changed to save data.
- Works for resources with a
--skip-aux-resources(Default:true) Aggressively skips requests for "auxiliary" content that hasn't been cached yet.- Blocked types:
video/*,audio/*,font/*,application/font-*,application/x-font-*. - Favicons: Any path starting with
/faviconand ending in.ico,.png, or.gif. - Response: Returns
204 No Contentfor these requests to stop the browser from waiting.
- Blocked types:
--image-scale <FLOAT>(Default:0.5) The scale factor for image dimensions.1.0means keep original size (but still re-compress).0.5means halve the width and height.- Set to
0.0to completely disable all image processing.
--image-scale-limit <MIN..MAX>(Default:96..384) Clamps the dimension calculated byimage-scale. The shorter side of the image will never be smaller thanMINor larger thanMAXpixels.--html-clean(Default:true) The master switch for HTML transformation. If disabled, Zhlob will not strip metadata, comments, or scripts, and will not clean link attributes.--html-rechunk-size <SIZE>(Default:1360) Sets the target size for network chunks.- Large chunks are split to this size.
- If set to
0, rechunking and asynchronous style loading are disabled.
--transform-limit <SIZE>(Default:5m) Safety threshold. Any resource with aContent-Lengthlarger than this (e.g., 5MB) will be passed through as-is. This prevents the proxy from exhausting memory or CPU when encountering massive files.--log-level <LEVEL>(Default:info) Log verbosity:off,error,warn,info,debug,trace.
Zhlob's dacgen command compiles standard text-based filter lists into a high-performance binary DAC state machine. Because it aims for maximum speed, only a subset of Adblock syntax is supported.
-
Simple Substrings:
tracker.js— matches the presence of the string anywhere in a script URL or inline code. -
Domain Anchors:
||example.com— matches the domain and all subdomains. -
Start Anchors:
|http://— matches patterns strictly at the start of a URL. -
Third-Party Restriction: Rules containing
$third-partyor$3p(requires PSL to function correctly). -
Type Filtering: Rules containing
$scriptor$all.
- Regex: Patterns enclosed in slashes
/.../. - Element Hiding: All CSS-based rules (
##,#@#, etc.). - End Anchors: Patterns ending in
|(e.g.,index.js|). - Wildcards: Patterns containing
*in the middle are skipped. - Content type: Content types that have no effect on
script - Advanced Options:
domain=,rewrite=,csp=,redirect=, etc., are ignored, and if they are required for the rule to be safe, the rule itself is typically skipped.
- Download filters: You can find sources in
download_ad_filters.sh. It is recommended to use: - Generate:
Providing
./zhlob dacgen --dac blocklist.dac --psl public_suffix_list.dat filter1.txt filter2.txt
--pslduring generation is optional but recommended as it helps the generator optimize certain domain-based rules.
- Run Zhlob once. It generates CA certificates in
~/.zhlob/. - Install
zhlob-ca-cert.cer(Windows/Android) orzhlob-ca-cert.pem(Other) as a Trusted Root CA in your system or browser. - Visit
http://mitm.itthrough the proxy for detailed instructions.