shemshad/laravel-blade-minify-plus

Minify final Laravel Blade HTML safely with first-class Laravel 8-13 support and beginner-friendly configuration.

Maintainers

Package info

github.com/arshaparthia/laravel-blade-minify-plus

pkg:composer/shemshad/laravel-blade-minify-plus

Statistics

Installs: 1 905

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

v1.2.0 2026-04-27 18:06 UTC

This package is auto-updated.

Last update: 2026-04-27 18:13:42 UTC


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)

  1. Publish config:
php artisan vendor:publish --tag=blade-minify-plus-config
  1. Add middleware to route(s):
use Illuminate\Support\Facades\Route;

Route::view('/about', 'about')->middleware('minify');
  1. 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.php
  • examples/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-level voku/html-min flags.

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 options at 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