PHPackages                             williamthogersen/minifier - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. williamthogersen/minifier

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

williamthogersen/minifier
=========================

High-performance HTML minifier with Rust backend via PHP FFI. Provides fast, memory-safe HTML, CSS, and JavaScript minification using tokenized parsing.

1.0.0(5mo ago)13↓50%MITRustPHP ^7.4 || ^8.0

Since Nov 18Pushed 5mo agoCompare

[ Source](https://github.com/WilliamThogersen/html-minifier-php)[ Packagist](https://packagist.org/packages/williamthogersen/minifier)[ Docs](https://github.com/WilliamThogersen/html-minifier-php)[ RSS](/packages/williamthogersen-minifier/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

HTML Minifier
=============

[](#html-minifier)

[![Latest Version](https://camo.githubusercontent.com/1f8f0a501d0e91ac030c19729750a065b12f5a7d3805dbc041a34af0b2d2eec7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f56657273696f6e2d76312e302e302d626c7565)](https://github.com/WilliamThogersen/html-minifier/releases)[![License](https://camo.githubusercontent.com/5caa455d8debc46fb23abbadb45a733a937f3910a73fc875c2f7820468e1bb54/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e)](LICENSE)

A high-performance HTML minifier for PHP, powered by a Rust backend.

This library provides a simple and fast way to minify HTML, including inline CSS and JavaScript, using a robust token-based parser instead of regular expressions. It's designed for production use, offering significant performance gains over native PHP solutions.

Features
--------

[](#features)

- **Fast:** Minification is handled by a pre-compiled Rust library, making it significantly faster than pure PHP alternatives.
- **Reliable:** Uses a token-based parser, which is more accurate and safer than regex-based solutions.
- **Easy to Use:** Simple PHP API that's easy to integrate into any project.
- **Configurable:** Comes with sensible defaults but allows for fine-grained control over the minification process.
- **Cross-Platform:** Works on Linux macOS

Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- `ffi` PHP extension enabled

To check if the `ffi` extension is enabled, run:

```
php -m | grep ffi
```

If it's not listed, you'll need to enable it in your `php.ini` file:

```
ffi.enable=1
```

Installation
------------

[](#installation)

You can install the library via Composer:

```
composer require WilliamThogersen/minifier
```

Usage
-----

[](#usage)

### Basic Minification

[](#basic-minification)

```
use WilliamThogersen\Minifier\HTMLMinifier;

$minifier = new HTMLMinifier();

$html = '

           Hello,   world!

';

$minifiedHtml = $minifier->minify($html);

echo $minifiedHtml;
// Output: Hello, world!
```

### Using Custom Options

[](#using-custom-options)

You can customize the minification process by passing an options object to the `minify` method.

```
use WilliamThogersen\Minifier\HTMLMinifier;
use WilliamThogersen\Minifier\MinifierOptions;

$minifier = new HTMLMinifier();

$options = new MinifierOptions(
    removeComments: true,
    collapseWhitespace: true,
    minifyJs: false, // Don't minify inline JS
    minifyCss: false // Don't minify inline CSS
);

$minifiedHtml = $minifier->minify($html, $options);
```

### Pre-configured Option Sets

[](#pre-configured-option-sets)

The library also provides pre-configured option sets for common use cases:

- `MinifierOptions::default()`: The default, well-balanced set of options.
- `MinifierOptions::conservative()`: A more conservative set of options that prioritizes safety over aggressive minification.
- `MinifierOptions::minimal()`: A minimal set of options that only performs the most basic and safe transformations.

```
use WilliamThogersen\Minifier\MinifierOptions;

// Use the conservative options
$options = MinifierOptions::conservative();
$minifiedHtml = $minifier->minify($html, $options);
```

How It Works
------------

[](#how-it-works)

This library uses PHP's Foreign Function Interface (FFI) to call a pre-compiled Rust library (`.so`, `.dylib`, or `.dll`). The Rust library is responsible for the heavy lifting of parsing and minifying the HTML. This approach provides the speed of a compiled language like Rust with the convenience of a PHP library.

The compiled libraries for common architectures are included with the package, so you don't need to have Rust installed on your server.

Development
-----------

[](#development)

If you want to contribute to the project, you'll need to set up the development environment.

### Building the Rust Library

[](#building-the-rust-library)

The Rust library needs to be compiled from the source in the `rust/` directory. A build script is provided to simplify this process.

```
# Build the library for your current platform
bash build.sh
```

This will compile the Rust code and place the resulting library file in the `src/Lib/` directory.

### Running Tests

[](#running-tests)

The project uses PHPUnit for testing.

```
# Run all tests
composer test

# Run unit tests only
composer test:unit

# Run integration tests only
composer test:integration
```

License
-------

[](#license)

The MIT License (MIT). Please see the [LICENSE](LICENSE) file for more information.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance69

Regular maintenance activity

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

179d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0fb46c0db0ae7bc8ca4e01ba70bbd799076aa65629da6ecf59f5ad1a25a12366?d=identicon)[WilliamThogersen](/maintainers/WilliamThogersen)

---

Top Contributors

[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

composerffihigh-performancehtmlminifyminify-htmlphpjavascriptcssperformancecompressionhtmlminifyminifieroptimizationrustffiweb-performance

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/williamthogersen-minifier/health.svg)

```
[![Health](https://phpackages.com/badges/williamthogersen-minifier/health.svg)](https://phpackages.com/packages/williamthogersen-minifier)
```

###  Alternatives

[matthiasmullie/minify

CSS &amp; JavaScript minifier, in PHP. Removes whitespace, strips comments, combines files (incl. @import statements and small assets in CSS files), and optimizes/shortens a few common programming patterns.

2.0k30.5M336](/packages/matthiasmullie-minify)[fitztrev/laravel-html-minify

Minifies the HTML output of Laravel 4 applications

414211.4k](/packages/fitztrev-laravel-html-minify)[voku/html-min

HTML Compressor and Minifier

1804.7M39](/packages/voku-html-min)[stolz/assets

An ultra-simple-to-use assets management library

296519.2k8](/packages/stolz-assets)[sensiolabs/minify-bundle

Assets Minifier (CSS, JS) for Symfony &amp; Minify integration in Asset Mapper

5694.9k1](/packages/sensiolabs-minify-bundle)[hexydec/htmldoc

A token based HTML document parser and minifier. Minify HTML documents including inline CSS, Javascript, and SVG's on the fly. Extract document text, attributes, and fragments. Full test suite.

2610.3k3](/packages/hexydec-htmldoc)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
