PHPackages                             akankov/laravel-compress-html - 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. akankov/laravel-compress-html

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

akankov/laravel-compress-html
=============================

Laravel integration for the akankov/html-min HTML minifier: Blade @htmlmin directive, response middleware, and a publishable config-driven service provider.

v2.1.1(1mo ago)151.8k—9.3%MITPHPPHP 8.3.\* || 8.4.\* || 8.5.\*CI passing

Since May 7Pushed 1mo agoCompare

[ Source](https://github.com/akankov/laravel-compress-html)[ Packagist](https://packagist.org/packages/akankov/laravel-compress-html)[ Fund](https://ko-fi.com/alekseikankov)[ RSS](/packages/akankov-laravel-compress-html/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (8)Dependencies (53)Versions (13)Used By (0)

[![CI](https://github.com/akankov/laravel-compress-html/actions/workflows/ci.yml/badge.svg)](https://github.com/akankov/laravel-compress-html/actions/workflows/ci.yml)[![Latest Stable Version](https://camo.githubusercontent.com/680f1d37a016000b152e79f2a99aa4fb12a197779d213f4fc2a6ea10d7fa4411/687474703a2f2f706f7365722e707567782e6f72672f616b616e6b6f762f6c61726176656c2d636f6d70726573732d68746d6c2f76)](https://packagist.org/packages/akankov/laravel-compress-html)[![Monthly Downloads](https://camo.githubusercontent.com/547da202baafe9f7a5f69680d7d18a60e8bbaa8cd03a644d2a188dfced967b03/687474703a2f2f706f7365722e707567782e6f72672f616b616e6b6f762f6c61726176656c2d636f6d70726573732d68746d6c2f642f6d6f6e74686c79)](https://packagist.org/packages/akankov/laravel-compress-html)[![Dependents](https://camo.githubusercontent.com/bf097bf7041f9f2da0801413d6c1babe6ab4e585095d449daa80ec8d1bc21d51/687474703a2f2f706f7365722e707567782e6f72672f616b616e6b6f762f6c61726176656c2d636f6d70726573732d68746d6c2f646570656e64656e7473)](https://packagist.org/packages/akankov/laravel-compress-html)[![License](https://camo.githubusercontent.com/cd1e2493c3eef949a4a590cc600943eba9431631fa66226b2ee62d957f81b9f1/687474703a2f2f706f7365722e707567782e6f72672f616b616e6b6f762f6c61726176656c2d636f6d70726573732d68746d6c2f6c6963656e7365)](https://packagist.org/packages/akankov/laravel-compress-html)

laravel-compress-html
=====================

[](#laravel-compress-html)

Laravel integration for [`akankov/html-min`](https://packagist.org/packages/akankov/html-min) — adds a Blade `@htmlmin` block directive, an opt-in HTML response middleware, and a publishable config-driven service provider.

Requirements
------------

[](#requirements)

- PHP `8.3.* || 8.4.* || 8.5.*`
- Laravel 12.x or 13.x
- `akankov/html-min` `^2.9`

Install
-------

[](#install)

```
composer require akankov/laravel-compress-html
```

The service provider is registered automatically via Laravel's package auto-discovery (`extra.laravel.providers` in `composer.json`); no manual `config/app.php` edit is needed.

Optionally publish the config file to tune the 29 minifier toggles:

```
php artisan vendor:publish --tag=htmlmin-config
```

This drops `config/htmlmin.php` into your application — every key defaults to the engine's default, so you only need to edit the ones you want to flip.

Blade directive
---------------

[](#blade-directive)

```
@htmlmin

    {{ $user->name }}

@endhtmlmin
```

The block captures rendered output, then minifies it. Variables interpolated via `{{ $expr }}` are escaped by Blade *before* the buffer reaches the minifier, so it's safe to interpolate user data inside.

Response middleware
-------------------

[](#response-middleware)

Opt-in: the service provider does **not** push the middleware onto the global stack — register it explicitly where you want it.

Globally, in `bootstrap/app.php` (Laravel 12+):

```
use Akankov\LaravelCompressHtml\Http\MinifyHtmlResponseMiddleware;
use Illuminate\Foundation\Configuration\Middleware;

return Application::configure(basePath: dirname(__DIR__))
    // …
    ->withMiddleware(function (Middleware $middleware): void {
        $middleware->append(MinifyHtmlResponseMiddleware::class);
    })
    // …
    ->create();
```

Or per-route / per-group:

```
use Akankov\LaravelCompressHtml\Http\MinifyHtmlResponseMiddleware;

Route::middleware(MinifyHtmlResponseMiddleware::class)
    ->group(function (): void {
        // routes whose responses should be minified
    });
```

The middleware only touches `Illuminate\Http\Response` instances whose `Content-Type` first segment is `text/html`. JSON, streamed, and binary responses pass through unchanged.

What "pass through" covers, precisely:

- **Streamed responses** (`StreamedResponse`, `BinaryFileResponse`) are never buffered or minified — anything that is not a plain `Illuminate\Http\Response`is returned as-is.
- **Partial content** (`206` responses to range requests) is skipped by the same mechanism in practice — range responses are produced as binary-file or streamed responses; minifying a byte range of HTML would corrupt it.
- **ESI/SSI fragments** assembled by a proxy are minified per-fragment only if the proxy requests them as ordinary routes through this middleware — in that case each fragment is valid standalone HTML and minifies safely.

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

[](#configuration)

Every key in `config/htmlmin.php` is a snake\_case mirror of a property on `Akankov\HtmlMin\Config\MinifierOptions`. The provider converts them with `Str::camel()` when constructing the options object, so:

```
'remove_comments'    => true,    // → MinifierOptions::$removeComments
'sum_up_whitespace'  => true,    // → MinifierOptions::$sumUpWhitespace
'optimize_attributes' => true,   // → MinifierOptions::$optimizeAttributes
```

See the published config file for the full list of 29 keys with their defaults.

Artisan command
---------------

[](#artisan-command)

`html-min:check` minifies a file **in memory** and reports the byte savings — a CI/dev smoke-check for "did this template change inflate the page?" without writing anything to disk:

```
php artisan html-min:check resources/views/rendered/home.html
# Reduced from 48.2 KB to 41.7 KB (-13.5%)
```

It exits `0` on success and `1` if the file cannot be read.

Versioning
----------

[](#versioning)

This package follows [Semantic Versioning](https://semver.org/). From **1.0.0** onward the public surface — the `@htmlmin` directive, the `MinifyHtmlResponseMiddleware`, the `html-min:check` command, the published `config/htmlmin.php` keys, and the service-provider bindings — is stable; breaking changes are reserved for a new major version. The underlying engine is tracked via a caret constraint (`akankov/html-min: ^2.9`), so it picks up engine minor/patch releases automatically.

Tests
-----

[](#tests)

```
composer install
vendor/bin/phpunit
make ci         # cs-check + phpstan + rector-check + test
make coverage   # line coverage + 100% floor (needs pcov or xdebug)
```

The suite holds **100% line coverage**, enforced in CI.

License
-------

[](#license)

MIT

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance93

Actively maintained with recent releases

Popularity33

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.9% 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

Every ~5 days

Total

9

Last Release

35d ago

Major Versions

v0.4.0 → v1.0.02026-06-01

v1.0.0 → v2.0.02026-06-07

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1974569?v=4)[Aleksei Kankov](/maintainers/akankov)[@akankov](https://github.com/akankov)

---

Top Contributors

[![akankov](https://avatars.githubusercontent.com/u/1974569?v=4)](https://github.com/akankov "akankov (31 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

middlewarelaravelhtmlminifybladecompresshtml min

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/akankov-laravel-compress-html/health.svg)

```
[![Health](https://phpackages.com/badges/akankov-laravel-compress-html/health.svg)](https://phpackages.com/packages/akankov-laravel-compress-html)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.3M347](/packages/psalm-plugin-laravel)[moonshine/moonshine

Laravel administration panel

1.3k253.1k86](/packages/moonshine-moonshine)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M133](/packages/roots-acorn)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45444.2k1](/packages/pressbooks-pressbooks)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k30.2M151](/packages/laravel-cashier)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k15.1M136](/packages/laravel-pulse)

PHPackages © 2026

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