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

Laravel Minify Laravel Package

fahlisaputra/laravel-minify

A Laravel middleware package that minifies HTML, CSS, and JavaScript responses on the fly. Reduce page size and improve load times with simple configuration, optional caching, and support for custom minifier drivers—no build tools required.

View on GitHub
Deep Wiki
Context7

Getting Started

  • Install with composer require fahlisaputra/laravel-minify. For Laravel 13, use ^1.2.4, which added Laravel 13 support.
  • Publish the config if needed: php artisan vendor:publish --tag=laravel-minify (check the package README for the exact tag).
  • Register the package middleware in bootstrap/app.php or app/Http/Kernel.php, depending on your Laravel version. For most apps, add it to the web middleware group so normal HTML responses are minified automatically.
  • First use case: enable minification only in production/staging, load a normal Blade page, and confirm the response HTML has reduced whitespace/comments while the page still renders and behaves correctly.
  • Start by reviewing the package config for enable/disable flags, ignored paths, and any options that control what gets minified.

Implementation Patterns

  • Global web middleware: Add the minify middleware to the web group for site-wide HTML minification. This is the simplest day-to-day setup for marketing pages, blogs, and standard Blade apps.
  • Route-specific middleware: Apply the middleware only to public, cacheable routes. This is safer for admin panels, API responses, and debugging routes.
  • Environment gating: Enable minification in production and staging, disable it locally. This keeps local debugging and Blade error output readable.
  • Ignore lists: Use config-based exclusions for routes/paths that must preserve exact HTML, such as email previews, documentation pages, or third-party embedded content.
  • Cache-friendly workflow: Minify at response time for dynamic pages, but prefer static asset build minification for CSS/JS. Use this package for HTML response cleanup, not as a replacement for Vite/Mix production builds.
  • CI check: Add a smoke test that requests a representative page and asserts key content is present. This catches minifier regressions without requiring visual inspection of whitespace.

Gotchas and Tips

  • Minification can break whitespace-sensitive content. Test <pre>, <textarea>, inline SVG, and contenteditable areas carefully.
  • Inline JavaScript and CSS can be affected by aggressive minification. If pages break only when the middleware is enabled, disable minification for that route first.
  • Middleware order matters. Place the minify middleware after response-generating middleware but before final response termination if you rely on other middleware modifying HTML.
  • Signed URLs and exact string matching can be sensitive to HTML changes. If you use signed URLs in HTML attributes, verify they still validate after minification.
  • Debug by temporarily disabling the middleware or environment flag, then compare raw and minified responses. Check whether the issue is HTML minification or asset pipeline minification.
  • Laravel 13 support is the notable change in v1.2.4. If you are upgrading to Laravel 13, pin ^1.2.4; older releases may not declare compatibility.
  • Extension points are typically config-driven: ignored paths, enable flags, and middleware placement. Prefer these over forking the package unless you need custom minification behavior.
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.
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings
coleus/apps
seampact/laravel
emmyconceptng/laravel-ng-postcode
jjsquady/round-robin