Minify

A CSS and JavaScript minifier written in pure PHP that strips whitespace, comments, and combines files

Library
Composer
v1.3.75
2,045stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
53/100Fair
Development Activity0
Maintenance32
Community80
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
78/100Good
Architecture78
Code Quality76
Innovation74
Learning Curve85

Minify is a CSS and JavaScript minifier implemented entirely in PHP. It removes unnecessary whitespace and comments, combines multiple files, inlines CSS @import statements and small assets as data URIs, and applies a set of safe optimizations to shrink common code patterns, all without requiring Node.js or an external toolchain.

The library exposes a simple object API where you construct a CSS or JS minifier, add source strings or files, and write the minified result to a string or file. It also ships minifycss and minifyjs command-line scripts for use outside of PHP code, making it a practical choice for PHP asset pipelines.

What You Get

  • Separate CSS and JS minifier classes with a consistent add/minify API
  • Whitespace stripping, comment removal, and file combining
  • CSS @import inlining and embedding of small assets as data URIs
  • minifycss and minifyjs CLI scripts for shell/build usage
  • Optional PSR-6 cache integration for expensive minification runs

Common Use Cases

  • Minifying CSS and JavaScript assets inside a PHP application without a Node.js toolchain
  • Combining multiple stylesheets or scripts into a single minified file
  • Inlining CSS imports and small images to reduce HTTP requests
  • Running quick minification from the command line via the bundled scripts

Under The Hood

Architecture - The library centers on an abstract Minify base class (src/Minify.php) that manages source collection, extraction of strings/comments into placeholders, and the replace pipeline. CSS (src/CSS.php) and JS (src/JS.php) subclass it, each defining regex-driven rules for their language; CSS additionally resolves @import paths and can convert relative URLs using matthiasmullie/path-converter and embed small assets. Placeholder extraction protects literals so whitespace/comment stripping cannot corrupt strings.

Tech Stack - Pure PHP with a very low floor (>=5.3), depending only on ext-pcre and matthiasmullie/path-converter. Distributed as a Composer library with PSR-4 autoloading under MatthiasMullie\Minify, plus two CLI entry points in bin/. Optional PSR cache implementations plug in for caching.

Code Quality - The code is compact and heavily reliant on carefully crafted regular expressions, an inherently tricky approach that the project backs with an extensive PHPUnit suite under tests/ covering many CSS/JS edge cases. php-cs-fixer enforces style.

API Design - The public surface is minimal and predictable: instantiate, add() sources, minify() to a string or file. The same shape works for both CSS and JS, and the CLI scripts mirror it for non-PHP callers, keeping the learning curve low.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search