PHPackages                             vormkracht10/laravel-minify-html-middleware - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. vormkracht10/laravel-minify-html-middleware

Abandoned → [backstagephp/laravel-minify-html-middleware](/?search=backstagephp%2Flaravel-minify-html-middleware)Library[Utility &amp; Helpers](/categories/utility)

vormkracht10/laravel-minify-html-middleware
===========================================

This package minifies HTML responses in Laravel safely.

v4.0.1(2mo ago)6668↑25%[1 issues](https://github.com/backstagephp/laravel-minify-html-middleware/issues)MITPHPPHP ^8.2

Since Jan 23Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/backstagephp/laravel-minify-html-middleware)[ Packagist](https://packagist.org/packages/vormkracht10/laravel-minify-html-middleware)[ Docs](https://github.com/backstagephp/laravel-minify-html-middleware)[ GitHub Sponsors](https://github.com/vormkracht10)[ RSS](/packages/vormkracht10-laravel-minify-html-middleware/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (24)Versions (156)Used By (0)

Laravel HTML Minify Middleware
==============================

[](#laravel-html-minify-middleware)

[![Latest Version on Packagist](https://camo.githubusercontent.com/9dedcdbf26233a7d876db9e3bb48d448954e6da4008ba3594255d7538bb8e74b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6261636b73746167652f6c61726176656c2d6d696e6966792d68746d6c2d6d6964646c65776172652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/backstage/laravel-minify-html-middleware)[![GitHub Tests Action Status](https://camo.githubusercontent.com/5aa7c329534ff661159bb6dfb956c11932f4c2dce2aa406b6ea0079d209149cf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6261636b73746167657068702f6c61726176656c2d6d696e6966792d68746d6c2d6d6964646c65776172652f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/backstagephp/laravel-minify-html-middleware/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/f212dcdedbb854eb8d1dd6c097d5b4dbab50e69c38c9a77d0dc86151b14dd4df/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6261636b73746167657068702f6c61726176656c2d6d696e6966792d68746d6c2d6d6964646c65776172652f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/backstagephp/laravel-minify-html-middleware/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/b73b7ae2d510759142607cfae26ab0a35213708f9b335b8ec711f5a6d45955ff/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6261636b73746167652f6c61726176656c2d6d696e6966792d68746d6c2d6d6964646c65776172652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/backstage/laravel-minify-html-middleware)

A lightweight and efficient Laravel middleware package that automatically minifies HTML responses, reducing page size and improving load times. The package intelligently removes unnecessary whitespace, comments, and optimizes your HTML output while preserving functionality.

Features
--------

[](#features)

- **Automatic HTML Minification**: Minifies HTML responses on-the-fly with zero configuration required
- **Smart Detection**: Only processes HTML responses, automatically skipping JSON, AJAX requests, and other non-HTML content
- **Safe Minification**: Preserves content in sensitive elements like ``, ``, and `` tags
- **Framework-Aware**: Compatible with Livewire, Knockout.js, and other JavaScript frameworks
- **Configurable Transformers**: Choose which transformations to apply or create custom ones
- **Performance Optimized**: Minimal overhead with efficient regex-based transformations
- **Laravel 10, 11, and 12 Support**: Works seamlessly with modern Laravel versions

What Gets Minified?
-------------------

[](#what-gets-minified)

The package includes three built-in transformers:

1. **Remove Comments**: Strips HTML comments while preserving framework-specific comments (Livewire, Knockout.js)
2. **Remove Whitespace**: Eliminates unnecessary whitespace between tags and multiple spaces
3. **Trim Scripts**: Removes extra whitespace from within `` tags

**Before Minification:**

```
>

        My Page

               Welcome

                console.log('Hello World');

```

**After Minification:**

```
>My PageWelcomeconsole.log('Hello World');
```

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

[](#requirements)

- PHP 8.2 or higher
- Laravel 10.x, 11.x, or 12.x

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

[](#installation)

Install the package via Composer:

```
composer require backstage/laravel-minify-html-middleware
```

The package will automatically register its service provider.

### Publish Configuration

[](#publish-configuration)

Publish the configuration file to customize the transformers:

```
php artisan vendor:publish --tag="laravel-minify-html-middleware-config"
```

This will create a `config/minify-html.php` file with the following default configuration:

```
