- What does backstage/laravel-minify-html-middleware do?
- It is a Laravel HTTP middleware that minifies HTML responses on the fly by trimming whitespace and redundant markup. It works at the response layer, so you do not need to edit controllers, Blade templates, or routing. It is a subtree split of the Backstage CMS package, and the repository is read-only. It is most useful for server-rendered Blade pages with large, whitespace-heavy HTML.
- How do I install backstage/laravel-minify-html-middleware?
- Install it with Composer using composer require backstage/laravel-minify-html-middleware. The package has no database, queue, or storage requirements, so installation is limited to the dependency and middleware registration. Because the repository is a read-only subtree split, contribute changes through the main Backstage CMS package rather than the split repository.
- How do I register this HTML minify middleware in Laravel 10?
- In Laravel 10 and earlier, register the middleware in app/Http/Kernel.php. Add it to the global $middleware array if every HTML response should be minified, or to $middlewareGroups['web'] if you want to limit it to web routes. Avoid adding it to API groups where responses are JSON rather than HTML.
- How do I register the middleware in Laravel 11?
- In Laravel 11, register it in bootstrap/app.php using the withMiddleware callback. You can append it globally with $middleware->append(...) or add it to a specific group such as web. The exact class name and namespace should be confirmed from the package source or README before registering.
- Does this middleware support Laravel 11 and PHP 8.2?
- The integration notes describe Laravel 10/11 and PHP 8.2+ as the target stack, but the provided context does not include a declared support matrix. Check the package composer.json for its illuminate/http and PHP version constraints before installing. Also verify compatibility with Octane, Swoole, or RoadRunner if you use those runtimes.
- Will minifying HTML break pre, textarea, code, or script tags?
- Whitespace is semantically meaningful inside pre, textarea, code, script, style, SVG, and inline element boundaries, so these are the main hazard zones for any HTML minifier. The provided excerpt does not document the package's exclusion list, so validate fixture pages containing those elements before enabling it globally. Also diff pages that rely on Alpine x-* attributes, Vue template syntax, or Blade-escaped output.
- Does it minify JSON, streamed, or binary responses?
- A body-transforming HTML middleware should skip StreamedResponse, BinaryFileResponse, JsonResponse, SSE, and non-text/html Content-Type values. The provided context does not confirm the package's default guards, so verify this in the code or with targeted tests. API-only services and SPA or Inertia shells generally gain nothing from HTML whitespace minification.
- Will this conflict with gzip, ETag, or response caching?
- If the middleware rewrites the response body, Content-Length and ETag values must be recomputed or invalidated. Order it so minification runs before compression and before any cache or signing layer hashes the rendered body. Test the actual middleware stack because debug toolbars, CSP nonce injection, and response-caching packages can interact badly with late body changes.
- Can I enable minification only in production or disable it locally?
- The provided context does not confirm whether the package includes a config toggle or environment bypass. If it does not, register the middleware conditionally in app/Http/Kernel.php or bootstrap/app.php so it is only active in production. Keeping it off in local and staging environments makes debugging and response diffing much easier.
- Is this package safe and maintained enough for production?
- The evaluation flags limited public adoption, no evident third-party security review, and no observable bus factor, so treat it as a small unvetted dependency. Pin the version, review the minification logic, and build a response-diff harness across representative routes before enabling it globally. If your risk tolerance is low, compare it with CDN or web-server minification and more established HTML minifier alternatives.