PHPackages                             shemshad/laravel-blade-minify-plus - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. shemshad/laravel-blade-minify-plus

ActiveLibrary[Templating &amp; Views](/categories/templating)

shemshad/laravel-blade-minify-plus
==================================

Minify the final HTML output of your Laravel Blade views without breaking your pages. Supports Laravel versions 8 through 12.

v1.0.0(8mo ago)11.9k↓40%MITPHPPHP &gt;=8.1

Since Sep 21Pushed 8mo agoCompare

[ Source](https://github.com/arshaparthia/laravel-blade-minify-plus)[ Packagist](https://packagist.org/packages/shemshad/laravel-blade-minify-plus)[ RSS](/packages/shemshad-laravel-blade-minify-plus/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Laravel‑Blade‑Minify‑Plus
=========================

[](#laravelblademinifyplus)

`laravel-blade-minify-plus` is a lightweight package for Laravel 8 through 12 that minifies the final HTML produced by your Blade templates. Minified HTML reduces response sizes, improves the effectiveness of gzip compression and can deliver a small performance boost to your users without having to change your views. The underlying [voku/html‑min](https://packagist.org/packages/voku/html-min)library removes extra whitespace, comments and other unneeded characters without breaking the content structure. The result is cleaner HTML that is safe for dynamic pages and SEO.

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require shemshad/laravel-blade-minify-plus
```

The service provider is auto‑discovered by Laravel. If you are not using package discovery you can register it manually in your `config/app.php` file:

```
'providers' => [
    // ...
    BladeMinifyPlus\BladeMinifyPlusServiceProvider::class,
],
```

Version Compatibility &amp; Middleware Registration
---------------------------------------------------

[](#version-compatibility--middleware-registration)

This package provides a `MinifyHtmlMiddleware`. How you register and use it depends on your Laravel version.

### Laravel 10 (and earlier)

[](#laravel-10-and-earlier)

Register an alias in `app/Http/Kernel.php` (in newer Laravel 10 apps the property is called `$middlewareAliases`; older apps may still use `$routeMiddleware`):

```
// app/Http/Kernel.php
protected $middlewareAliases = [
    // ...
    'minify' => \BladeMinifyPlus\Middleware\MinifyHtmlMiddleware::class,
];
```

Configuration
-------------

[](#configuration)

Publish the configuration file to customize the behaviour:

```
php artisan vendor:publish --tag=blade-minify-plus-config
```

This will create a `config/blade-minify-plus.php` file where you can adjust the following options:

KeyDescription`enabled`Enable or disable minification globally.`skip_routes`Array of named routes that should **not** be minified. Useful for APIs or routes that render JSON/XML.`options`A map of booleans corresponding to the methods exposed by `voku\HtmlMin`. These options allow you to fine‑tune the minification process. For example, `doRemoveComments` controls whether HTML comments are stripped and `doRemoveWhitespaceAroundTags` removes unnecessary whitespace between tags.The default options are conservative; many of the more aggressive transformations are disabled by default to avoid breaking pages. You can experiment with enabling them if you wish to squeeze out a few more bytes.

Usage
-----

[](#usage)

### Route middleware

[](#route-middleware)

The package registers a middleware alias named `minify`. You can apply minification to a specific route or group:

```
Route::get('/about', function () {
    return view('about');
})->middleware('minify');

Route::middleware(['minify'])->group(function () {
    Route::view('/', 'welcome');
    Route::view('/contact', 'contact');
});
```

### Global middleware (optional)

[](#global-middleware-optional)

If you wish to enable minification for **all** web routes, add the `MinifyHtmlMiddleware` to the `web` middleware group in your `app/Http/Kernel.php`:

```
protected $middlewareGroups = [
    'web' => [
        // ... existing middleware ...
        \BladeMinifyPlus\Middleware\MinifyHtmlMiddleware::class,
    ],
];
```

Alternatively you can uncomment the `pushMiddlewareToGroup` call in `BladeMinifyPlusServiceProvider` to automatically append the middleware to the `web` group whenever the package is enabled.

### Skipping minification

[](#skipping-minification)

Some pages—such as ones that return JSON, serve files, or use complex JavaScript frameworks—may not benefit from HTML minification. You can exclude them in two ways:

- Set the `skip_routes` array in the configuration to the names of the routes you wish to ignore.
- Disable minification on a per‑route basis by simply omitting the `minify` middleware from that route or group.

How it works
------------

[](#how-it-works)

When a request is processed, the `MinifyHtmlMiddleware` inspects the response. If the response is HTML, the middleware passes the content through a configured `HtmlMinifier` instance which uses the `voku/html‑min` library to optimise it. Non‑HTML responses (JSON, XML, binary files) and routes listed in `skip_routes` are left untouched. The minifier supports a rich set of flags that control how aggressively optimisation should be applied. By default only safe optimisations such as removing comments and compressing excess whitespace are enabled.

Laravel’s own `HTMLMin\HTMLMin` package warns that forcing optimisations can be dangerous and recommends enabling them only when you understand the implications. With Blade‑Minify‑Plus you remain in control: minification is opt‑in via middleware and each option can be tuned to your needs.

Testing
-------

[](#testing)

To ensure minification isn’t silently breaking pages, you can write feature tests that assert your views still contain expected strings. You may also dump the response body locally and visually inspect it before enabling minification in production. Remember to clear your view cache whenever changing Blade templates:

```
php artisan view:clear
```

Compatibility
-------------

[](#compatibility)

This package supports Laravel versions 8.x through 12.x. It requires PHP 8.1 or newer. Because it relies on Laravel’s middleware stack, it does not need to touch the Blade compiler and thus remains forward compatible with future releases.

Security and contribution
-------------------------

[](#security-and-contribution)

If you discover a security vulnerability, please open an issue or submit a pull request. Contributions are welcome; feel free to file issues or pull requests to improve the package.

License
-------

[](#license)

Blade‑Minify‑Plus is open‑source software licensed under the MIT license.

Laravel 12 Setup (Kernel-less)
------------------------------

[](#laravel-12-setup-kernel-less)

Register the middleware in `bootstrap/app.php` as shown in `examples/bootstrap.app.l12.php`.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance62

Regular maintenance activity

Popularity22

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

240d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4c3ccfb5411c127a8eaa4d0ae71db99e10ea198b9a734a77a8a907d687ae60d4?d=identicon)[shemshad](/maintainers/shemshad)

---

Top Contributors

[![arshaparthia](https://avatars.githubusercontent.com/u/21290330?v=4)](https://github.com/arshaparthia "arshaparthia (2 commits)")

---

Tags

middlewarelaravelhtmlminifyblade

### Embed Badge

![Health badge](/badges/shemshad-laravel-blade-minify-plus/health.svg)

```
[![Health](https://phpackages.com/badges/shemshad-laravel-blade-minify-plus/health.svg)](https://phpackages.com/packages/shemshad-laravel-blade-minify-plus)
```

###  Alternatives

[fitztrev/laravel-html-minify

Minifies the HTML output of Laravel 4 applications

414211.4k](/packages/fitztrev-laravel-html-minify)[robsontenorio/mary

Gorgeous UI components for Livewire powered by daisyUI and Tailwind

1.5k454.7k15](/packages/robsontenorio-mary)[yocmen/html-minify

Minifies the HTML output of Laravel 5 applications (Originally from https://github.com/fitztrev/laravel-html-minify)

1713.7k](/packages/yocmen-html-minify)[ken/blade-minify

Laravel Blade Minify

128.9k1](/packages/ken-blade-minify)[stijnvanouplines/blade-country-flags

A package to easily make use of country flags in your Laravel Blade views.

26307.2k6](/packages/stijnvanouplines-blade-country-flags)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
