nervo/yuicompressor
A PHP/Laravel wrapper around Yahoo's YUI Compressor that minifies CSS and JavaScript straight from your application. Use it to shrink asset files for production and reduce page load times, often wired into build or asset pipelines. Lightly maintained with limited adoption, so review before relying o...
composer.json, the README, and vendor/nervo/yuicompressor. This package’s last release was in 2013, so assume Laravel 4/PHP 5-era conventions until proven otherwise.composer require nervo/yuicompressor
// app/config/app.php
'providers' => [
'Nervo\YuiCompressor\YuiCompressorServiceProvider',
],
'aliases' => [
'YuiCompressor' => 'Nervo\YuiCompressor\Facades\YuiCompressor',
],
php artisan config:publish nervo/yuicompressor
# or, on newer Laravel:
php artisan vendor:publish
java -version
YUI Compressor is a Java tool. The package may bundle a .jar or expect a path to one.$source = File::get(public_path('css/app.css'));
$minified = YuiCompressor::compress($source, 'css'); // confirm actual method name in source
File::put(public_path('css/app.min.css'), $minified);
If the facade exposes css() / js() helpers instead of a generic compress(), use those; the important pattern is “read source, minify once, write output.”// app/Console/Commands/MinifyAssets.php
public function handle()
{
$assets = [
['in' => public_path('css/app.css'), 'out' => public_path('css/app.min.css'), 'type' => 'css'],
['in' => public_path('js/app.js'), 'out' => public_path('js/app.min.js'), 'type' => 'js'],
];
foreach ($assets as $asset) {
$source = File::get($asset['in']);
$minified = YuiCompressor::compress($source, $asset['type']);
File::put($asset['out'], $minified);
}
}
class AssetMinifier
{
public function minify(string $path, string $type): string
{
return YuiCompressor::compress(File::get($path), $type);
}
}
@if (app()->environment('production'))
<link rel="stylesheet" href="{{ asset('css/app.min.css') }}">
<script src="{{ asset('js/app.min.js') }}"></script>
@else
<link rel="stylesheet" href="{{ asset('css/app.css') }}">
<script src="{{ asset('js/app.js') }}"></script>
@endif
php artisan assets:minify
php artisan config:cache
exec, shell_exec, or proc_open must not be disabled.escapeshellarg() for any path you control and validate all file locations.let, const, arrow functions, async, classes, and many ES6+ features can fail or produce bad output. Transpile to ES5 first or use a modern minifier.app.min.css beside app.css, or rewrite URLs after minification.public/css, public/js, and any temp directory used by the package.How can I help you explore Laravel packages today?