backstage/laravel-minify-html-middleware
A Laravel middleware that minifies HTML responses on the fly, trimming whitespace and redundant markup to shrink payloads and speed up page delivery without touching your views or blade templates.
Architecture fit
handle()/terminate(). This is idiomatic, requires no changes to controllers, views, or routing, and composes with the existing kernel stack.Integration feasibility
composer require, then registration in app/Http/Kernel.php (Laravel ≤10) or bootstrap/app.php (Laravel 11). A competent Laravel engineer can integrate and validate in under a day.Technical risk
<pre>, <textarea>, <code>, inline element boundaries (whitespace between inline-blocks renders as a space), <script>/<style> bodies, <script type="application/ld+json">, IE conditional comments, SVG, and framework attributes containing template syntax (Alpine x-*, Vue {{ }}, Blade-escaped output).Content-Length and ETag, clients on keep-alive connections can truncate or hang; if it runs after a compression middleware, output is corrupted. Streamed and binary responses must be explicitly skipped, as must non-text/html content types.Key questions
pre/textarea/script/style?StreamedResponse, BinaryFileResponse, JsonResponse, SSE, and non-HTML Content-Type values by default?Content-Length and invalidate/regenerate ETag?Stack fit
Migration path
composer.json (avoid ^ for an unvetted package).MINIFY_HTML_ENABLED) defaulting to false in local and staging.web middleware group so it observes the final body after session, auth, and any injectors, but before the response leaves the framework.Compatibility
laravel-page-speed or similar); choose one.<script> tags, confirm the minifier preserves attribute values byte-for-byte.Sequencing
Maintenance
composer audit in CI, and re-review on every Laravel major upgrade since middleware signature and kernel registration change between majors.Support
Scaling
pcre.backtrack_limit.Failure modes
<pre> formatting, mangled inline scripts. Detected only by visual regression testing; this is the highest-probability failure.Content-Length after body rewrite, causing hangs or truncation on keep-alive HTTP/1.1.preg_* failures on unusually large or pathological documents producing 500s; typically route-scoped and hard to reproduce.Content-Length/ETag recomputation, visual regression snapshots in CI, and a global kill switch.Ramp-up
TPM recommendation
How can I help you explore Laravel packages today?