shemshad / laravel-blade-minify-plus
Minify final Laravel Blade HTML safely with first-class Laravel 8-13 support and beginner-friendly configuration.
Package info
github.com/arshaparthia/laravel-blade-minify-plus
pkg:composer/shemshad/laravel-blade-minify-plus
Requires
- php: >=8.1
- illuminate/support: ^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
- voku/html-min: ^4.5
README
laravel-blade-minify-plus is a lightweight package that minifies the final HTML output of Blade views.
It is designed to be easy for beginners and stable for production projects.
Why use this package?
- Reduces HTML size by removing unnecessary whitespace/comments.
- Keeps Blade templates unchanged (works at the response layer).
- Safe defaults that avoid aggressive transformations.
- Supports Laravel 8, 9, 10, 11, 12, and 13.
Requirements
- PHP 8.1+
- Laravel 8.x – 13.x
Installation
composer require shemshad/laravel-blade-minify-plus
Laravel auto-discovers the service provider. If auto-discovery is disabled, register it manually:
// config/app.php 'providers' => [ // ... BladeMinifyPlus\BladeMinifyPlusServiceProvider::class, ],
Quick Start (2 minutes)
- Publish config:
php artisan vendor:publish --tag=blade-minify-plus-config
- Add middleware to route(s):
use Illuminate\Support\Facades\Route; Route::view('/about', 'about')->middleware('minify');
- Open your page and inspect the response HTML.
Laravel version setup
Laravel 11, 12, and 13 (bootstrap/app.php)
Use middleware aliases in bootstrap/app.php:
use BladeMinifyPlus\Middleware\MinifyHtmlMiddleware; use Illuminate\Foundation\Application; use Illuminate\Foundation\Configuration\Middleware; return Application::configure(basePath: dirname(__DIR__)) ->withRouting( web: __DIR__.'/../routes/web.php', commands: __DIR__.'/../routes/console.php', ) ->withMiddleware(function (Middleware $middleware) { $middleware->alias([ 'minify' => MinifyHtmlMiddleware::class, ]); // Optional: apply to all web routes. // $middleware->appendToGroup('web', MinifyHtmlMiddleware::class); }) ->create();
A full example is available in:
examples/bootstrap.app.l12.phpexamples/bootstrap.app.l13.php
Laravel 10 and earlier (Kernel)
Register middleware alias in app/Http/Kernel.php:
protected $middlewareAliases = [ // ... 'minify' => \BladeMinifyPlus\Middleware\MinifyHtmlMiddleware::class, ];
For older app skeletons, use $routeMiddleware instead of $middlewareAliases.
Configuration
After publishing, edit config/blade-minify-plus.php.
Main options
enabled(bool): Global on/off switch.skip_routes(array): Route names that should not be minified.options(array): Low-levelvoku/html-minflags.
Example
return [ 'enabled' => env('BLADE_MINIFY_PLUS_ENABLED', true), 'skip_routes' => [ 'api.docs', 'webhooks.receive', ], 'options' => [ 'doRemoveComments' => true, 'doSumUpWhitespace' => true, ], ];
How compatibility is preserved across Laravel versions
This package keeps compatibility by:
- Registering only a middleware alias in the service provider.
- Avoiding hard coupling to app-kernel internals.
- Minifying only eligible HTML responses.
- Skipping streamed/file responses and non-HTML content types.
This means Laravel 13 support is added without breaking Laravel 8-12 behavior.
Tips for beginners
- Start with route-level middleware first (
->middleware('minify')). - Test a few pages before enabling globally.
- Keep advanced
optionsat defaults unless you need deeper optimization. - If a page behaves unexpectedly, add its route name to
skip_routes.
Development checks
php -l src/BladeMinifyPlusServiceProvider.php php -l src/Middleware/MinifyHtmlMiddleware.php php -l config/blade-minify-plus.php
License
MIT