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

Minify Laravel Package

devfactory/minify

A Laravel middleware that automatically minifies HTML responses, removing unnecessary whitespace, comments, and redundant markup to shrink payloads and speed up page loads. Easy to install and configurable per route, it reduces output size without changing your views or build setup.

View on GitHub
Deep Wiki
Context7

Getting Started

composer require devfactory/minify

Where to look first:

  1. vendor/devfactory/minify/README.md — the usage surface is small.
  2. vendor/devfactory/minify/src/ — confirm the real class names. The package is a thin wrapper (82 stars, last release 2023-02-15, 0 dependents); it most likely delegates to matthiasmullie/minify, so the Minify\CSS / Minify\JS classes will feel familiar.
  3. vendor/devfactory/minify/composer.json — check extra.laravel.providers and extra.laravel.aliases. If a service provider/facade is registered, use the package facade; if not, add it manually to config/app.php.

First use case — minify one file at deploy time:

use MatthiasMullie\Minify;

$css = new Minify\CSS(base_path('resources/legacy/app.css'));
$css->minify(public_path('assets/app.min.css'));

$js = new Minify\JS(base_path('resources/legacy/app.js'));
$js->minify(public_path('assets/app.min.js'));

If the package exposes a Laravel facade, the call looks more like:

use DevFactory\Minify\Facades\Minify;

Minify::css(['resources/legacy/app.css'])
      ->minify(public_path('assets/app.min.css'));

Don't assume the facade name — open src/ after install and copy the exact API.

Implementation Patterns

Minify at build/deploy, never per request. Wrap the minifier in an Artisan command (php artisan assets:minify) or a Composer script and run it during deployment. Per-request minification burns CPU and produces no cache benefit.

Combining many files. Use add() to concatenate in order — order is significant for CSS cascade and JS globals:

$js = new Minify\JS();
$js->add(public_path('js/vendor.js'))
   ->add(public_path('js/app.js'))
   ->minify(public_path('assets/bundle.min.js'));

Cache-bust in Blade. Store the output under public/assets/ and version the URL by mtime so browsers get the fresh file:

function asset_min(string $file): string {
    $path = public_path("assets/{$file}");
    return asset("assets/{$file}") . '?v=' . filemtime($path);
}

Inline minification. The same objects accept strings, which is handy for CMS-provided snippets or Blade partials:

$css = new Minify\CSS();
$css->add($inlineCss);
echo $css->minify();

Cache invalidation. Decide once where the "source of truth" lives. A common pattern is to hash source mtimes into a cache key, skip regeneration if the key matches, and otherwise rewrite the output file — this makes the deploy step idempotent.

Coexist with Vite/Mix. Use this package only for legacy asset trees, or for one-off files that don't fit your bundler. Don't run it over Vite's already-hashed build output; you'll double-minify and lose source maps.

CI guardrail. Add a step that runs the minifier and then git diff --exit-code public/assets so stale committed bundles fail the build.

Gotchas and Tips

  • Source maps are not produced. If you depend on source maps for debugging, keep unbundled originals in dev and only run this in staging/production builds.
  • Relative url() in CSS breaks. Minification doesn't rewrite paths. If app.css at resources/legacy/ references url(../img/logo.png) and you output to public/assets/app.min.css, the path resolves differently. Either output next to the source or rewrite paths yourself.
  • @import handling is ambiguous. Some minifiers inline imports, some leave them. Test a representative file and check whether @import survived.
  • JS minification is lexical, not semantic. It won't tree-shake, and it can break old code that relies on specific whitespace or comments (conditional-compilation comments, //@ sourceMappingURL, legacy IE conditional comments). Run node --check on the output as a cheap smoke test.
  • Inline </script> in JS strings will prematurely close a <script> block if you echo minified JS into a Blade view. Escape to <\/script> at the boundary.
  • Laravel auto-discovery is not guaranteed. With 0 dependents and a low score, verify by running php artisan package:discover -v; if the facade isn't listed, register the provider and alias manually.
  • No service provider means no config. If no config/minify.php is publishable, treat the package as a plain library — configure via constructor arguments and your own thin wrapper class.
  • PHP version support. Last release was Feb 2023. On PHP 8.3+ check for deprecation notices by running with error_reporting(E_ALL); if it's a wrapper around matthiasmullie/minify, upgrading that dependency alone may fix issues.
  • Pin the version. Output can change between releases, which will trip the CI diff guardrail. Commit composer.lock and the minified artifacts together.
  • Debugging a broken build. Minify one file at a time, diff against the original, then bisect the file list. If it's the wrapped matthiasmullie library, set its debug option to preserve more of the source for comparison.
  • Exit ramp is trivial. Because the package is a thin wrapper, wrapping it in your own AssetMinifier service means you can swap to esbuild, lightningcss, or matthiasmullie/minify directly without touching every call site.
  • Bus factor. 0 dependents and one minor release means low community testing. If you hit a bug, fork or vendor the dependency rather than waiting for an upstream fix.
  • Extension points. Subclass the minifier classes (or your wrapper) to add pre/post hooks — e.g., an autoprefixer pass before CSS minification, or a header comment banner after.
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.
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle
glavweb/extra-bundle
glavweb/api-bundle
glavweb/admin-bundle
adachsoft/api-version-bundle
elsayed85/laravel-api-exceptions
ouhssini/laravel-demo-mode
daworks/ncloud-outbound-mailer-driver
gp247/cms
ignibyte/aic-gates
nexa-merchant/blog
novasa/laravel-language-center
opencage/geocode
adolfoholzer/parameters
livenetworks/ln-starter
cgv/localized-resource