- How do I install graham-campbell/htmlmin in a Laravel application?
- Install it with composer require graham-campbell/htmlmin:9.0.1. Laravel auto-discovery registers the service provider and facade, then you register the middleware in bootstrap/app.php on Laravel 11+ or app/Http/Kernel.php on Laravel 10 and below. Publish the config with vendor:publish if you want to tune skip rules. Confirm the package's PHP and Laravel constraints before adopting it.
- Which Laravel versions does graham-campbell/htmlmin support?
- The evaluation covers v9.0.1 and shows middleware registration for Laravel 11+ in bootstrap/app.php and for Laravel 10 and below in app/Http/Kernel.php. Because v9.0.1 is a patch on a major boundary, verify the exact PHP and Laravel constraints in composer.json against both your current runtime and your next planned upgrade. Treat a Laravel major upgrade as a smoke-test trigger rather than assuming compatibility.
- Should I register the HTMLMin middleware globally or only on specific routes?
- Prefer route scoping over global registration. Register a named middleware alias and apply it to a route group that serves server-rendered Blade pages, so JSON APIs, file downloads, Horizon, Telescope, and similar tooling endpoints never traverse the minifier. Global registration is simpler but expands the response path and the blast radius unnecessarily.
- Will graham-campbell/htmlmin break Blade pages with pre, textarea, or inline JavaScript?
- Yes, it can, if you apply it to pages with whitespace-sensitive output. Minifiers can silently corrupt pre, textarea, inline script and style blocks, and framework directives in attributes such as Alpine x-*, Vue mustaches, or HTMX. These failures produce no exception or log entry, so build a rendered-page parity check and an exclusion list before enabling it broadly.
- Does graham-campbell/htmlmin work with Inertia, SPA backends, or JSON APIs?
- It is a poor fit for JSON APIs, Inertia or SPA backends, binary downloads, and responses already minified or compressed by nginx or a CDN. The middleware is designed for server-rendered Blade surfaces such as marketing pages, content sites, admin dashboards, and legacy apps without a frontend build step. On non-HTML responses it adds per-request CPU for no user-visible benefit.
- Can I minify HTML with HTMLMin outside middleware, such as in a job or custom response?
- Yes. The package exposes a programmatic entry point, app(HTMLMin::class)->minify($html), for jobs, custom transformers, or places where middleware is awkward. Keep the same exclusions in mind as with middleware, because the minifier sees serialized markup rather than the Blade source. Test the resulting HTML for whitespace-sensitive regions.
- How do I configure or disable HTMLMin in production?
- Publish the package config with vendor:publish and use its skip or ignore settings to keep sensitive routes and content out of the minifier. Route-level middleware aliases are the clearest kill switch because you can remove them from a group or route. If you rely on a config flag, verify it takes effect without a deploy and clear cached configuration after changes.
- Is Laravel HTML minification redundant if nginx or my CDN already compresses HTML?
- Check your edge stack first. If nginx or the CDN already minifies HTML or serves pre-compressed content, Laravel-side minification is redundant and may waste per-request CPU. Also confirm how the middleware handles Content-Encoding and streaming or chunked responses before enabling it on routes that stream output.
- How should I test that graham-campbell/htmlmin does not change rendered output?
- Test semantic render parity, not byte-for-byte equality, across a representative set of rendered pages. Include pages with pre, textarea, inline script and style, CSP-nonced JavaScript, and Alpine, Vue, or HTMX attributes, and assert that those regions remain valid. Run the same smoke suite after Laravel or package upgrades, because the Blade compiler is the fragile integration seam and failures may not appear in error-rate monitoring.
- Is graham-campbell/htmlmin actively maintained, and what is the contingency?
- Adoption signals are weak: the evaluation notes zero stars, zero dependents, and a composite score of 0.3, so you would be the validating adopter rather than benefiting from a known install base. Pin the exact version through your validation window and define a fork-or-replace contingency. Review maintainer footprint and release cadence before making it a standing dependency.