JShrink

A native PHP JavaScript minifier that shrinks JS with a single static call.

Library
Composer
vv1.8.1
763stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
43/100Fair
Development Activity0
Maintenance20
Community72
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
76/100Good
Architecture72
Code Quality78
Innovation60
Learning Curve92

JShrink is a PHP class that minifies JavaScript so it can be delivered to clients faster. Unlike many alternatives it is a native PHP implementation rather than a port of a JavaScript tool, which gives it better performance when minifying code on the fly inside a PHP application.

Minification is exposed through a single static Minifier::minify call that strips whitespace and comments while optionally preserving flagged comments. It is well suited to asset pipelines and frameworks that need to compress JavaScript at build or request time without shelling out to an external Node-based toolchain.

What You Get

  • A one-call static API: JShrink\Minifier::minify($js) returns the minified string
  • A native PHP implementation with no dependency on Node or external minifier binaries
  • An option to preserve flagged (important) comments during minification
  • A small, focused, well-tested codebase installable via Composer

Common Use Cases

  • Minifying JavaScript inside a PHP asset pipeline or framework build step
  • Compressing inline or bundled JS at request time (with caching) on PHP-only hosts
  • Reducing JavaScript payload size without adding a Node-based toolchain

Under The Hood

Architecture - The entire library is a single class, JShrink\Minifier, in src/JShrink/Minifier.php. Its public static minify method instantiates the minifier, walks the JavaScript source character by character through a small state machine that tracks strings, regular-expression literals and comments, and emits the stripped output. Options such as flaggedComments control comment retention.

Tech Stack - Pure PHP supporting PHP 7 and 8, installed via Composer with PSR-0 autoloading. Development uses PHPUnit for tests, PHP-CS-Fixer for style, and php-coveralls for coverage reporting, wired through GitHub Actions.

Code Quality - The codebase is deliberately tiny and covered by a PHPUnit suite under tests, with CI running on pull requests and coverage tracked via Coveralls. The single-responsibility design keeps the surface area small and auditable.

API Design - Developer experience is excellent for its scope: one static call returns the minified string, with an optional associative-array of flags for the few tunables. There is essentially no setup or learning curve beyond reading a two-line example.

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