Weave Code
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

Minify Laravel Package

mrclay/minify

Minify is a PHP asset server for combining and compressing JS/CSS with cache-friendly headers, conditional GET, long Expires, and CSS URL rewriting. Note: no longer regularly maintained and may break modern JS/CSS; use newer tooling.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Use Case Alignment: The mrclay/minify package remains a front-end asset optimization tool, but the 4.0.2 release introduces SCSS/SASS compatibility via scssphp 2.x, expanding its utility for Laravel applications using Laravel Mix or Vite with SCSS preprocessing. This aligns better with modern Laravel workflows where SCSS is prevalent.
    • Key Leverage Points:
      • SCSS Support: Can now minify preprocessed SCSS assets without requiring manual conversion to CSS, reducing pipeline complexity.
      • Backward Compatibility: Maintains support for traditional CSS/JS minification, ensuring no disruption to existing workflows.
      • Middleware/Service Provider Integration: Still ideal for runtime minification (e.g., dynamic asset generation) or as a post-processor in build pipelines.
    • Anti-Patterns:
      • Overhead for Static Assets: Runtime minification (even with SCSS) may still introduce latency for CDN-hosted assets. Pre-minification (e.g., via Laravel Mix/Vite) remains preferable for static deployments.
      • SCSS Parsing Risks: While scssphp 2.x improves compatibility, complex SCSS (e.g., @import with variables) may still require validation to avoid minification failures.

Integration Feasibility

  • Core Laravel Compatibility:
    • PHP/SCSSPHP Dependency: Now requires scssphp/scssphp (v2.x), adding a minor dependency but enabling SCSS support. Verify compatibility with Laravel’s PHP version (8.1+).
    • Laravel Mix/Vite Integration:
      • Laravel Mix: Can be integrated as a post-CSS processor (e.g., via mix.js() or mix.sass() hooks).
      • Vite: Requires a custom plugin to invoke minification post-SCSS compilation (see Vite Plugin Guide).
    • Dependency Conflicts: Low risk, but test with scssphp/scssphp@^2.0 to avoid version clashes.

Technical Risk

Risk Area Severity Mitigation Strategy
SCSS Parsing Errors Medium Validate SCSS input; use scssphp’s built-in error handling.
Performance Overhead Medium Benchmark SCSS minification vs. CSS; cache aggressively.
Cache Invalidation Medium Integrate with Laravel’s cache tags or event system (e.g., asset-changed).
Dependency Bloat Low scssphp is lightweight; monitor for future breaking changes.
Security Risks Low Sanitize SCSS input paths; restrict to trusted assets.

Key Questions

  1. SCSS Workflow:
    • Will this replace Laravel Mix/Vite’s built-in SCSS processing, or supplement it (e.g., runtime minification for dynamic SCSS)?
  2. Fallback for SCSS Failures:
    • How will the system handle malformed SCSS (e.g., syntax errors, missing dependencies)?
  3. Caching Strategy for SCSS:
    • How will minified SCSS assets be cached (file-based, Redis, CDN)?
    • What’s the invalidation strategy for updated SCSS files?
  4. Dynamic SCSS:
    • Are there user-specific SCSS variables/themes requiring runtime minification?
  5. Build Tool Integration:
    • For Vite/Laravel Mix, should minification occur during build (preferred) or runtime?
  6. Monitoring:
    • How will SCSS minification performance (e.g., compilation time) be measured post-integration?

Integration Approach

Stack Fit

  • Best Fit Scenarios:
    • SCSS-Heavy Applications: Ideal for Laravel apps using SCSS (e.g., with Laravel Mix or Vite) where runtime minification is needed (e.g., dynamic themes).
    • Hybrid Pipelines: Can act as a post-processor for both CSS and SCSS in build tools (e.g., minify after Vite compiles SCSS).
    • Legacy Systems: Modernizes asset delivery without requiring SCSS-to-CSS conversion.
  • Less Ideal Scenarios:
    • Static Site Generators: Overkill if using JAMstack tools (e.g., Next.js with next-sass).
    • CDN-Optimized Workflows: Pre-minification via build tools (e.g., Vite) is more efficient.
  • Tech Stack Synergy:
    • Laravel Mix: Integrate via postCss or sass hooks to minify SCSS post-compilation.
    • Vite: Use a custom plugin to invoke minification after SCSS processing.
    • Symfony Components: Leverage Symfony’s HTTP cache for minified SCSS assets.
    • Queue Workers: Offload SCSS minification to background jobs for large files.

Migration Path

  1. Assessment Phase:
    • Audit SCSS usage (e.g., resources/scss/ files, Laravel Mix/Vite config).
    • Identify assets eligible for minification (e.g., vendor SCSS, theme files).
  2. Pilot Integration:
    • Option A (Runtime Middleware): Add middleware to minify SCSS/CSS on request (fallback to original if SCSS fails).
      // app/Http/Middleware/MinifyAssets.php
      public function handle(Request $request, Closure $next) {
          $response = $next($request);
          $contentType = $response->headers->get('Content-Type');
          if (str_contains($contentType, 'css')) {
              try {
                  $minified = minify($response->getContent());
                  return new Response($minified, $response->status(), $response->headers);
              } catch (\Exception $e) {
                  // Fallback to original
                  return $response;
              }
          }
          return $response;
      }
      
    • Option B (Build-Time Integration): For Vite/Laravel Mix, use a plugin to minify SCSS post-compilation (preferred for static assets).
  3. Incremental Rollout:
    • Start with non-critical SCSS assets (e.g., vendor libraries).
    • Monitor performance (TTFB, cache hit ratio, SCSS compilation time).
  4. Full Adoption:
    • Replace legacy minification tools (e.g., postcss-cli).
    • Integrate with Laravel’s cache system for persistence.

Compatibility

  • Laravel Versions:
    • Tested on Laravel 9+ (PHP 8.1+). For older versions, ensure scssphp/scssphp@^2.0 compatibility.
  • Asset Types:
    • New: Supports SCSS (with scssphp 2.x).
    • Existing: Still supports CSS and JavaScript.
    • Limitations:
      • No support for LESS or PostCSS-only workflows (requires pre-processing).
      • Complex SCSS (e.g., @use rules) may need validation.
  • Environment Variables:
    • Extend .env for SCSS-specific configs:
      MINIFY_ENABLED=true
      MINIFY_CACHE_DRIVER=redis
      MINIFY_SCSS_ENABLED=true
      MINIFY_EXCLUDE_PATTERNS=["admin/*", "*.scss.bak"]
      

Sequencing

  1. Pre-requisites:
    • Install scssphp/scssphp@^2.0: composer require scssphp/scssphp.
    • Enable PHP dom and fileinfo extensions.
    • Set up cache driver (Redis recommended for scaling).
  2. Core Integration:
    • Install package: composer require mrclay/minify.
    • Publish config: php artisan vendor:publish --provider="MrClay\Minify\MinifyServiceProvider".
  3. Middleware/Plugin Setup:
    • For runtime: Register middleware in app/Http/Kernel.php.
    • For build-time: Configure Vite/Laravel Mix plugins (see example).
  4. Testing:
    • Unit test SCSS minification (mock HTTP requests with SCSS input).
    • Load test with realistic SCSS files (e.g., large theme files).
  5. Monitoring:
    • Track SCSS compilation time and cache hit/miss ratios.
    • Alert on SCSS minification failures (e.g., syntax errors).

Operational Impact

Maintenance

  • Proactive Tasks:
    • Cache Management: Clear minified SCSS cache during deployments (e.g., via php artisan cache:clear).
    • Dependency Updates: Monitor mrclay/minify and scssphp/scssphp for breaking changes.
    • SCSS Validation: Periodically audit SCSS files for minification errors (e.g., using scss --check).
  • Reactive Tasks:
    • Fallback Logic: Ensure graceful degradation for failed SCSS minification (serve original or cached versions).
    • Log Monitoring:
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.
bugban/symfony
beyonder-capi/workflow-extensions-bundle
beyonder-capi/job-queue-bundle
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin