PHPackages                             rzl-zone/blade-minify - 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. rzl-zone/blade-minify

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

rzl-zone/blade-minify
=====================

A Laravel package to seamlessly minify Blade HTML output for faster pages and a better user experience.

v0.0.5(1mo ago)011↓50%MITPHPPHP ^8.1

Since Jun 14Pushed 1mo agoCompare

[ Source](https://github.com/rzl-zone/blade-minify)[ Packagist](https://packagist.org/packages/rzl-zone/blade-minify)[ Docs](https://github.com/rzl-zone/blade-minify)[ GitHub Sponsors](https://github.com/rzl-app)[ RSS](/packages/rzl-zone-blade-minify/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (5)Dependencies (10)Versions (6)Used By (0)

 [ ![RzlZone Logo](https://raw.githubusercontent.com/rzl-zone/rzl-zone/main/logo-circle.png) ](https://raw.githubusercontent.com/rzl-zone/rzl-zone/main/logo-circle.png)

**Blade Minify**
================

[](#blade-minify)

  *Blazing-Fast Output Minifier for [`Laravel`](https://laravel.com) Blade Views.*
 ***Blade Minify** automatically minifies your rendered HTML output, stripping unnecessary whitespaces and comments to ensure smaller page sizes and optimal load times.*
 ***Built with ❤️ by [@rzl-zone](https://github.com/rzl-zone).***

 [ ![Latest Version on Packagist](https://camo.githubusercontent.com/275ff576c5599b4562d13dc7d6ebf344c3c72a685fc87f8fcc0c7b6574e9a832/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f727a6c2d7a6f6e652f626c6164652d6d696e6966792e7376673f6c6f676f3d7061636b6167697374266c6162656c3d4c617465737425323056657273696f6e2532305061636b616769737426636f6c6f723d726564266c6f676f436f6c6f723d7768697465267374796c653d666c61742d726f756e646564) ](https://packagist.org/packages/rzl-zone/blade-minify) [ ![Total Downloads on Packagist](https://camo.githubusercontent.com/e63e478017297da67b163c4c1fd5e7f399b181169bad751a1d48888e497a416f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f727a6c2d7a6f6e652f626c6164652d6d696e6966792e7376673f6c6f676f3d7061636b6167697374266c6162656c3d546f74616c253230446f776e6c6f6164732532305061636b616769737426636f6c6f723d6f72616e6765266c6f676f436f6c6f723d7768697465267374796c653d666c61742d726f756e646564) ](https://packagist.org/packages/rzl-zone/blade-minify) [ ![PHPStan Level](https://camo.githubusercontent.com/1fb18cc8ee49b1c75bb0156d1646dbcefb6ab66871ff8f6783f386c0b816de07/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068707374616e2d6c6576656c253230382d627269676874677265656e3f7374796c653d666c61742d726f756e646564) ](https://phpstan.org) [ ![PHP Version](https://camo.githubusercontent.com/c55ec293b6eab5f351624ac4212390379cf7507b61dae14fd9d4f6ba49ea56ab/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d5e382e312d626c75653f7374796c653d666c61742d726f756e646564) ](https://www.php.net) [ ![Laravel Version](https://camo.githubusercontent.com/50aefa2b9c25ef693943171d9ad8e8accfd6e841ca40ec03ff5e33086a1809fe/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d5e31302e782532307c2532305e31312e782532307c2532305e31322e782532307c2532305e31332e782d7265643f7374796c653d666c61742d726f756e646564) ](https://laravel.com) [ ![Illuminate Support](https://camo.githubusercontent.com/e69f53e5874ce2b58906a4b51583005be6ec8d880ba5634ed7481935d627972e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f496c6c756d696e617465253246737570706f72742d5e31302e782532307c2532305e31312e782532307c2532305e31322e787c2532305e31332e782d626c75653f7374796c653d666c61742d726f756e646564) ](https://laravel.com) [ ![GitHub](https://camo.githubusercontent.com/9dbd75c70b3135f5c7ea00c97257a0eb7b75687c4042cc659f526634d67200c6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5265706f2d6f6e2532304769744875622d3138313731373f6c6f676f3d676974687562267374796c653d666c61742d726f756e646564) ](https://github.com/rzl-zone/blade-minify) [ ![Repo on GitHub](https://camo.githubusercontent.com/7875de22fb0f9a2d8b1b6b1007979324c9d0e5d28f5f8942dc04f19444334358/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4f72672d727a6c2d2d7a6f6e652d3234323932653f6c6f676f3d676974687562267374796c653d666c61742d726f756e646564) ](https://github.com/orgs/rzl-zone/repositories)

---

📚 Table of Contents
-------------------

[](#-table-of-contents)

- 🛠 [Requirements](#user-content-requirements)
- ⚙️ [Installation](#user-content-installation)
- 🚀 [Setup](#user-content-setup)
- 🔥 [Usage](#user-content-usage)
- ℹ️ [Programmatic Manual Operations](#user-content-programmatic-manual-operations)
- ℹ️ [Inline Blade Directive Isolation](#user-content-inline-blade-directive-isolation)
- ⚡️ [Advanced Integration with Vite &amp; React Fast Refresh](#user-content-advanced-integration-with-vite-and-react-fast-refresh)
- 📦 [Custom Vite Architecture Mapping](#user-content-custom-vite-architecture-mapping)
- ⚙️ [Environment Tailoring Examples](#user-content-environment-tailoring-examples)
- 🛠 [How to consume these in `vite.config.js`](#user-content-how-to-consume-in-vite-config)
- 💻 [Blade Implementation Usage](#user-content-blade-implementation-usage)
- 📝 [Changelog](#user-content-changelog)
- 🤝 [Contributing](#user-content-contributing)
- ❤️ [Become a Sponsor](#user-content-become-a-sponsor)
- 🛡 [Security](#user-content-security)
- 🙌 [Credits](#user-content-credits)
- 📜 [License](#user-content-license)
- 🔗 [Framework &amp; Reference Links](#user-content-framework--reference-links)

---

🛠 Requirements
--------------

[](#-requirements)

Laravel Framework &amp; `illuminate/support`PHP^10.x | ^11.x | ^12.x | ^13.x^8.1---

⚙️ Installation
---------------

[](#️-installation)

You can install the package via composer:

```
composer require rzl-zone/blade-minify
```

---

🚀 Setup
-------

[](#-setup)

1. Install Package

    ```
    composer require rzlzone/blade-minify
    ```
2. Publish Configuration

    ```
    php artisan vendor:publish --tag=RzlZoneBladeMinify
    ```

### That's It 🎉

[](#thats-it-)

The package automatically registers its service provider and middleware through Laravel's package discovery system.

No additional setup is required for Laravel 10, 11, 12, or 13.

### Optional Manual Registration

[](#optional-manual-registration)

#### Service Provider

[](#service-provider)

> Only required if Laravel Package Discovery has been disabled.

```
'providers' => [
    \RzlZone\BladeMinify\Providers\RzlBladeMinifyServiceProvider::class,
],
```

### Middleware

[](#middleware)

> The package automatically registers its middleware by default.
> Manual registration is only necessary if you prefer to manage the middleware yourself.

#### Laravel 10

[](#laravel-10)

Add the middleware to the `web` middleware group in `app/Http/Kernel.php`:

```
protected $middlewareGroups = [
    'web' => [
        \RzlZone\BladeMinify\Middleware\RzlBladeOutputMinifier::class,

        // Other middleware...
    ],
];
```

#### Laravel 11, 12 &amp; 13

[](#laravel-11-12--13)

Add the middleware to the `web` middleware group in `bootstrap/app.php`:

```
->withMiddleware(function (Middleware $middleware) {
    $middleware->web(append: [
        \RzlZone\BladeMinify\Middleware\RzlBladeOutputMinifier::class,
    ]);
})
```

---

🔥 Usage
-------

[](#-usage)

### Enable in .env

[](#enable-in-env)

```
RZLZONE_MINIFY_ENABLE=true
```

### Disable in .env

[](#disable-in-env)

```
RZLZONE_MINIFY_ENABLE=false
```

### Minify only in production

[](#minify-only-in-production)

```
RZLZONE_MINIFY_ONLY_PROD=true
```

### Minify at all mode APP Env (default)

[](#minify-at-all-mode-app-env-default)

```
RZLZONE_MINIFY_ONLY_PROD=false
```

### Ignore specific route names from minifying render output

[](#ignore-specific-route-names-from-minifying-render-output)

```
'ignore_route_name' => [
  // 'dashboard',
  // 'home',
]
```

---

ℹ️ Programmatic Manual Operations
---------------------------------

[](#ℹ️-programmatic-manual-operations)

```
use RzlZone\BladeMinify\Facades\RzlBladeMinify;

// Manually compress a raw HTML layout string
$compressedHtml = RzlBladeMinify::minify("  Hello World  ");

// Explicitly isolate a string container from compression cycles
$isolatedHtml = RzlBladeMinify::ignoreMinify("  preserve   whitespace  ");
```

---

ℹ️ Inline Blade Directive Isolation
-----------------------------------

[](#ℹ️-inline-blade-directive-isolation)

To prevent specific code segments or third-party blocks from being targeted by the regex compression loops, wrap your code inside the dedicated wrapper directive:

```
{{-- Everything inside this directive block remains completely raw and uncompressed --}}
@ignoreRzlzoneMinify

     Strictly   Preserved   Preformatted   Whitespace   Output

@endIgnoreRzlzoneMinify
```

---

⚡️ Advanced Integration with Vite &amp; React Fast Refresh
----------------------------------------------------------

[](#️-advanced-integration-with-vite--react-fast-refresh)

No special layout modifications or fragile workarounds are required.
The package natively tracks, isolates, and guards core asset bundler structures—such as React Fast Refresh preambles—ensuring strict security tokens and javascript scopes are preserved post-minification.

---

📦 Custom Vite Architecture Mapping
----------------------------------

[](#-custom-vite-architecture-mapping)

Publishing the configuration creates the `custom-vite` block inside `config/rzlzone-blade-minify.php`. This gives you full control over customized asset folders, CSP nonces, and hot-reload file parameters:

```
