承接 williamthogersen/minifier 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

williamthogersen/minifier

Composer 安装命令:

composer require williamthogersen/minifier

包简介

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

README 文档

README

Latest Version 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

  • 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

  • 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

You can install the library via Composer:

composer require WilliamThogersen/minifier

Usage

Basic Minification

use WilliamThogersen\Minifier\HTMLMinifier;

$minifier = new HTMLMinifier();

$html = '
    <div class="container">
        <p style="color: red;">   Hello,   world!   </p>
    </div>
';

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

echo $minifiedHtml;
// Output: <div class=container><p style=color:red>Hello, world!</p></div>

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

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

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

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

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

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

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

williamthogersen/minifier 适用场景与选型建议

williamthogersen/minifier 是一款 基于 Rust 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 11 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「performance」 「compression」 「javascript」 「css」 「html」 「minify」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 williamthogersen/minifier 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 williamthogersen/minifier 我们能提供哪些服务?
定制开发 / 二次开发

基于 williamthogersen/minifier 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 29
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: Rust

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-18