AdBlock Compiler
A modern, TypeScript-based compiler-as-a-service for adblock filter lists with real-time progress tracking, visual diff, and production-ready features.
Overview
AdBlock Compiler is a Deno-native rewrite of the original @adguard/hostlist-compiler with significant improvements for production use. It provides the same functionality with enhanced performance, Cloudflare Workers support, and a comprehensive API.
β¨ Key Features
π― Multi-Source Compilation
Combine filter lists from URLs, files, or inline rules with automatic format detection and validation.
β‘ Performance Optimizations
Gzip compression (70-80% size reduction), request deduplication, smart caching with 1-hour TTL.
π Circuit Breaker
Automatic retry with exponential backoff for unreliable sources (3 retries, smart error handling).
π Visual Diff
See what changed between compilations with color-coded diffs showing added, removed, and unchanged rules.
πͺ Batch Processing
Compile up to 10 filter lists in parallel with a single API request.
π‘ Event Pipeline
Real-time progress tracking via Server-Sent Events (SSE) with detailed compilation stages.
π Universal Runtime
Works in Deno, Node.js, Cloudflare Workers, and browsers with zero build configuration.
π¨ 11 Transformations
Deduplicate, compress, validate, remove comments, and moreβall applied in optimized order.
π Quick Start
Installation
# Install from JSR (recommended)
deno add jsr:@jk-com/adblock-compiler
# Or run directly without installation
deno run jsr:@jk-com/adblock-compiler/cli
Basic Usage
import { compile } from '@jk-com/adblock-compiler';
// Compile from configuration
const rules = await compile({
name: "My Filter List",
sources: [
{
source: "https://example.com/filters.txt"
}
],
transformations: ["Deduplicate", "RemoveEmptyLines"]
});
console.log(`Compiled ${rules.length} rules`);CLI Usage
# Compile from config file
deno run jsr:@jk-com/adblock-compiler/cli -c config.yaml
# Show version
deno run jsr:@jk-com/adblock-compiler/cli --version
π Web Interface & API
AdBlock Compiler is deployed as a production service with a full-featured web interface and REST API.
π Web UI
Interactive web interface with Simple Mode, Advanced Mode, examples, and real-time compilation progress.
π API Endpoint
RESTful API with JSON responses, SSE streaming, and batch processing endpoints.
API Endpoints
- GET /api - API information and examples
- POST /compile - Compile with JSON response
- POST /compile/stream - Compile with SSE progress
- POST /compile/batch - Compile multiple lists in parallel
Example API Request
curl -X POST https://adblock-compiler.jayson-knight.workers.dev/compile \
-H "Content-Type: application/json" \
-d '{
"configuration": {
"name": "My Filter List",
"sources": [
{"source": "https://example.com/filters.txt"}
],
"transformations": ["Deduplicate", "RemoveEmptyLines"]
}
}'π Performance Features
Caching with Compression
Compilation results are cached with gzip compression for 1 hour. Cache is automatically invalidated when configuration changes. Compression typically achieves 70-80% size reduction.
Request Deduplication
Identical concurrent requests are automatically deduplicated. Only one compilation executes, with all requests receiving the same result. Check the X-Request-Deduplication: HIT header.
Circuit Breaker
External source downloads include:
- Timeout: 30 seconds per request
- Retry Logic: Up to 3 retries with exponential backoff
- Retry Conditions: 5xx errors, 429 rate limits, timeouts
- No Retry: 4xx client errors (except 429)
Rate Limiting
- Limit: 10 requests per minute per IP address
- Response: HTTP 429 with
Retry-After: 60header - Batch Limit: Maximum 10 compilations per batch request
π§ Configuration
AdBlock Compiler supports the same configuration schema as the original hostlist-compiler, ensuring compatibility with existing configurations.
Configuration Example (YAML)
name: My Filter List
description: Custom ad-blocking filter
version: "1.0.0"
sources:
- name: Local Rules
source: data/local.txt
type: adblock
- name: EasyList
source: https://easylist.to/easylist/easylist.txt
transformations:
- RemoveModifiers
- Validate
transformations:
- Deduplicate
- RemoveEmptyLines
- InsertFinalNewLine
exclusions:
- "*.google.com"
- "/analytics/"Available Transformations
- ConvertToAscii - Convert internationalized domains
- TrimLines - Remove whitespace
- RemoveComments - Strip comments
- Compress - Convert hosts to adblock syntax
- RemoveModifiers - Remove unsupported modifiers
- InvertAllow - Convert to allowlist
- Validate - Remove invalid rules
- ValidateAllowIp - Validate but keep IPs
- Deduplicate - Remove duplicates
- RemoveEmptyLines - Clean empty lines
- InsertFinalNewLine - Add final newline
π Documentation & Resources
GitHub Repository
Source code, issue tracker, and contribution guidelines.
API Documentation
Complete API reference with examples and client code.
Client Libraries
Python, TypeScript/JavaScript, and Go client implementations.
π Comparison with Original
AdBlock Compiler is a drop-in replacement for @adguard/hostlist-compiler with additional features:
| Feature | Original | AdBlock Compiler |
|---|---|---|
| Core Compilation | β | β |
| 11 Transformations | β | β |
| Cloudflare Workers | β | β |
| Gzip Compression | β | β |
| Request Deduplication | β | β |
| Circuit Breaker | β | β |
| Visual Diff | β | β |
| Batch Processing API | β | β |
| SSE Event Pipeline | β | β |
| Web UI | β | β |
Next Steps
Try the Web UI
Test the compiler with the interactive web interface.
Getting Started
Learn how to integrate AdBlock Compiler into your workflow.
View on GitHub
Explore the source code and contribute to development.