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.

v1.0.0(1w ago)122.9k↓10.6%MITPHPPHP 8.3.\* || 8.4.\* || 8.5.\*CI passing

Since May 7Pushed 2d 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 1w ago

READMEChangelog (7)Dependencies (39)Versions (10)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.8`

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.

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.8`), 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

Maintenance99

Actively maintained with recent releases

Popularity32

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity57

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

Every ~5 days

Total

6

Last Release

8d ago

Major Versions

v0.4.0 → v1.0.02026-06-01

### Community

Maintainers

![](https://www.gravatar.com/avatar/ed013f7318c9a6acff086c2c588b6c4ed2089dac3df56d95884367ec79764001?d=identicon)[akankov](/maintainers/akankov)

---

Top Contributors

[![akankov](https://avatars.githubusercontent.com/u/1974569?v=4)](https://github.com/akankov "akankov (22 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

3325.1M337](/packages/psalm-plugin-laravel)[moonshine/moonshine

Laravel administration panel

1.3k239.9k72](/packages/moonshine-moonshine)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9732.3M121](/packages/roots-acorn)[tallstackui/tallstackui

TallStackUI is a powerful suite of Blade components that elevate your workflow of Livewire applications.

719160.4k12](/packages/tallstackui-tallstackui)[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.

45344.0k1](/packages/pressbooks-pressbooks)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

76318.2M110](/packages/laravel-mcp)

PHPackages © 2026

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