nitra/php-min
PhpMin is a Composer-ready PHP port of the classic CssMin and JsMinPlus tools. It provides simple minification/formatting utilities for CSS and JavaScript assets, packaged for easy installation and use in PHP projects.
Use Case Alignment: The nitra/php-min package provides CSS/JS minification, which is a core optimization need for performance-critical applications (e.g., SPAs, marketing sites, or high-traffic APIs with embedded assets). It fits well in:
yui-compressor) is deprecated.Laravel Synergy:
mix-manifest.json processing).Alternatives Comparison:
| Feature | nitra/php-min |
Laravel Mix (Terser) | PHP Built-in (file_get_contents + JSMin) |
|---|---|---|---|
| CSS Support | ✅ Yes | ❌ (CSS via PostCSS) | ❌ No |
| JS Support | ✅ Yes | ✅ (Terser) | ✅ (Basic) |
| Async Processing | ❌ No | ✅ Yes | ❌ No |
| Laravel Native | ✅ (Service Provider) | ✅ (Mix) | ❌ No |
| Maintenance | ⚠️ Low Stars | ✅ Actively Maintained | ❌ Deprecated |
Verdict: Prefer nitra/php-min for CSS + JS minification in PHP-native environments (e.g., legacy apps or custom pipelines). For modern Laravel apps, Laravel Mix/Vite is superior due to async processing and broader tooling.
uglify-js or cssnano), reducing deployment complexity.Minifier facade).@stack/@push directives in Blade or middleware for runtime minification.mix.version() or response()->header('Cache-Control')).// config/minifier.php
return [
'enabled' => env('MINIFY_ASSETS', false),
'js_engine' => 'closure', // or 'google'
'css_engine' => 'yui',
];
// app/Providers/AppServiceProvider.php
public function boot()
{
if (config('minifier.enabled')) {
Minifier::minifyJs($jsCode);
Minifier::minifyCss($cssCode);
}
}
yui-compressor, uglify-js)?postcss (via Laravel Mix) suffice?laravel-mix/vite’s Terser integration adequate?| Tool | Role |
|---|---|
| Laravel Mix/Vite | Build-time minification (preferred). |
| Cloudflare | Edge-side minification/CDN caching. |
spatie/laravel-honeypot |
Security if minifying UGC. |
yui-compressor, manual sed/gzip).nitra/php-min vs. alternatives (e.g., php-minify).mix.js()/mix.css() with a custom Laravel Mix plugin:
// resources/js/bootstrap.js
const minifier = require('nitra/php-min');
module.exports = {
processJs: (src) => minifier.minifyJs(src),
processCss: (src) => minifier.minifyCss(src),
};
// app/Http/Middleware/MinifyAssets.php
public function handle($request, Closure $next) {
$response = $next($request);
if ($response->headers->get('Content-Type') === 'text/css') {
$content = $response->getContent();
$response->setContent(Minifier::minifyCss($content));
}
return $response;
}
composer.json access.composer require nitra/php-min.config/minifier.php.robots.txt/sitemap.xml (if critical).config/minifier.php.How can I help you explore Laravel packages today?