JShrink
A native PHP JavaScript minifier that shrinks JS with a single static call.
Repository Health
Technical Analysis
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.
Used by 2 apps in this directory
FreeScout
Customer Support
Run your own help desk and shared inbox — a fully self-hosted, open-source alternative to Zendesk and Help Scout with no per-agent fees.
matomo
Analytics
Open-source, privacy-first web and app analytics that puts you in complete control of your data.