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: 60 header
  • 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

  1. ConvertToAscii - Convert internationalized domains
  2. TrimLines - Remove whitespace
  3. RemoveComments - Strip comments
  4. Compress - Convert hosts to adblock syntax
  5. RemoveModifiers - Remove unsupported modifiers
  6. InvertAllow - Convert to allowlist
  7. Validate - Remove invalid rules
  8. ValidateAllowIp - Validate but keep IPs
  9. Deduplicate - Remove duplicates
  10. RemoveEmptyLines - Clean empty lines
  11. 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:

FeatureOriginalAdBlock 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.