Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Yuicompressor Laravel Package

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...

Deep Wiki
Context7

Getting Started

  • Check compatibility before wiring anything: read 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.
  • Install with Composer, pinning the version if needed:
    composer require nervo/yuicompressor
    
  • Register the service provider and facade for older Laravel apps. Verify exact class names in the package source/README, but the pattern is:
    // app/config/app.php
    'providers' => [
        'Nervo\YuiCompressor\YuiCompressorServiceProvider',
    ],
    
    'aliases' => [
        'YuiCompressor' => 'Nervo\YuiCompressor\Facades\YuiCompressor',
    ],
    
  • Publish the package config if it ships one:
    php artisan config:publish nervo/yuicompressor
    # or, on newer Laravel:
    php artisan vendor:publish
    
  • Confirm Java is available before debugging Laravel:
    java -version
    
    YUI Compressor is a Java tool. The package may bundle a .jar or expect a path to one.
  • First use case: minify a compiled CSS or JS file during deploy/build, not on every request.
    $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.”

Implementation Patterns

  • Put minification in an Artisan command or deployment script:
    // 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);
        }
    }
    
  • Wrap the package behind your own small service so the abandoned API does not leak through the app:
    class AssetMinifier
    {
        public function minify(string $path, string $type): string
        {
            return YuiCompressor::compress(File::get($path), $type);
        }
    }
    
  • Use minified assets only in production:
    @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
    
  • In deployment/CI, run the minification step after asset compilation and before config caching:
    php artisan assets:minify
    php artisan config:cache
    
  • Fail the build if output is empty or the process fails. A silent minifier failure can ship broken assets.
  • For modern Laravel, treat this as a legacy migration candidate: use Vite/Mix or a maintained minifier for new projects, and only keep this package where its Laravel 4-era integration already exists.

Gotchas and Tips

  • This package is effectively abandoned: last release 2013, low star count, and likely tied to Laravel 4-era service provider/facade conventions. Modern Laravel auto-discovery, PHP 7/8, and Composer platform checks may all reject it.
  • Java is the hidden runtime dependency. Production must have a JRE, the jar must be readable/executable, and exec, shell_exec, or proc_open must not be disabled.
  • If the package shells out to Java, never pass user-controlled paths or content. Use escapeshellarg() for any path you control and validate all file locations.
  • Old YUI Compressor versions do not understand modern JavaScript: 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.
  • CSS relative URLs can break when the minified file is written to a different directory. Keep app.min.css beside app.css, or rewrite URLs after minification.
  • Keep source files and source maps. YUI Compressor does not produce useful modern source maps, so debugging minified JS in production is painful.
  • Prefer absolute paths for the Java binary and jar in production. Config caching may not behave well with this old package, so using env/config values explicitly is safer.
  • Watch file permissions: the deploy user must be able to write public/css, public/js, and any temp directory used by the package.
  • Write outputs atomically where possible: minify to a temporary file, validate it is non-empty, then rename it into place.
  • Do not repeatedly minify already-minified vendor bundles. Concatenate and minify application assets once, and leave vendor assets to their own build pipeline.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings
coleus/apps
seampact/laravel
emmyconceptng/laravel-ng-postcode
jjsquady/round-robin