- How do I install fahlisaputra/laravel-minify in a Laravel app?
- Install it with composer require fahlisaputra/laravel-minify, then optionally publish the config file and register the middleware in your HTTP kernel or on a route group. There is no build step and no Node dependency, so setup is limited to Composer and middleware registration. Pin the exact version, such as 1.2.4, while you validate the output in your own application.
- Which Laravel and PHP versions does laravel-minify support?
- Release 1.2.4 is a Laravel 13 support declaration, which suggests the maintainer is tracking framework majors rather than letting the package decay. That release note is a compatibility claim, not proof of a CI test matrix, so check the illuminate/support constraint and run your own smoke tests on your Laravel version. Also read the package composer.json for its PHP floor before installing on an older runtime.
- How do I register the minify middleware so it only runs on certain routes?
- Register it in the web middleware group in bootstrap/app.php on Laravel 11 and later, or in app/Http/Kernel.php on older versions, or attach it directly to individual route groups. The safer pattern is a narrow group covering only public, server-rendered pages instead of a global registration. Keep an explicit exclusion list for admin panels, API routes, and download endpoints.
- Does laravel-minify break Blade components, Alpine.js, Livewire, or pre and textarea content?
- Rewriting HTML can break whitespace-sensitive output such as pre and textarea blocks, inline elements where inter-tag whitespace is meaningful, conditional comments, and CSP nonces, and it can interfere with Alpine.js directives and Livewire attributes. Blade components that emit inline script or style blocks deserve particular attention. Diff the rendered output of representative pages before and after enabling the middleware rather than assuming it is safe.
- Does this package handle Content-Length, ETag, and gzip or Brotli compression correctly?
- This is the main production risk with any response-rewriting middleware: if the body length changes without a matching Content-Length or ETag update, clients and caches can serve truncated or stale responses. Verify the behaviour in front of your CDN, full-page cache, and existing compression layer before shipping. If you cannot confirm it, run the middleware only where response caching is not in play.
- Will laravel-minify minify JSON API responses, file downloads, or streamed responses?
- Do not assume the middleware inspects content type and skips JSON, XML, streamed, or file-download responses; the safe assumption is that it does not unless you have verified it. Enumerate exclusions explicitly for API routes, webhooks, and download endpoints. Blanket registration on an application that also serves JSON is the classic misuse of this kind of package.
- What does the optional caching in laravel-minify do and is it safe in production?
- Caching stores minified output so repeat requests skip re-minification, which reduces CPU on the request hot path. The trade-off is invalidation: a cached entry can outlive a template change and serve stale markup. If you enable it, clear the cache as part of every deploy and confirm the cache key accounts for per-route differences.
- Can I use a custom minifier driver instead of the built-in one?
- The package supports custom minifier drivers, so you can swap in your own implementation when the default output does not suit your HTML. Implement the driver contract the package expects and point the config entry at your class. Keep the built-in driver available so you can fall back quickly if a custom one misbehaves.
- How do I test that minification does not break my pages before deploying?
- Add feature tests that assert on status codes and key rendered fragments, since byte-exact whitespace assertions will need loosening. Better, capture rendered HTML with the middleware disabled and enabled, then diff a sample of representative pages including forms, code samples, and inline scripts. Also assert that excluded routes are genuinely bypassed.
- Is laravel-minify still maintained, and what are the alternatives?
- It is a small, single-maintainer package; the prompt Laravel 13 release is reassuring but does not change the long-term support profile, so watch issue triage and any open correctness bugs against Blade, Alpine, or Livewire output. Alternatives include renatomarinho/laravel-page-speed, build-time minification, or simply relying on compression at the reverse proxy or CDN. For many applications the extra byte savings over gzip are marginal and not worth the response-mutation risk.