PHPackages                             djdigitalemedien/laravel-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. djdigitalemedien/laravel-minify

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

djdigitalemedien/laravel-minify
===============================

Minify your blade views, html, css and js files on the fly for Laravel 6, 7, 8, 9 and 10

013PHP

Since Oct 11Pushed 1y ago1 watchersCompare

[ Source](https://github.com/djdigitalemedien/Laravel-Minify)[ Packagist](https://packagist.org/packages/djdigitalemedien/laravel-minify)[ RSS](/packages/djdigitalemedien-laravel-minify/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

NOTE
----

[](#note)

Fork of

---

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

[](#installation)

Minify for Laravel requires PHP 7.2 or higher. This particular version supports Laravel 8.x, 9.x, 10.x, and 11.x.

To get the latest version, simply require the project using [Composer](https://getcomposer.org):

```
composer require djdigitalemedien/laravel-minify
```

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

[](#configuration)

Minify for Laravel supports optional configuration. To get started, you'll need to publish all vendor assets:

```
php artisan vendor:publish --provider="djdigitalemedien\Minify\MinifyServiceProvider"
```

This will create a config/minify.php file in your app that you can modify to set your configuration. Also, make sure you check for changes to the original config file in this package between releases.

Register the Middleware (Laravel 10 or older)
---------------------------------------------

[](#register-the-middleware-laravel-10-or-older)

In order Minify for Laravel can intercept your request to minify and obfuscate, you need to add the Minify middleware to the `app/Http/Kernel.php` file:

```
protected $middleware = [
    ....
    // Middleware to minify CSS
    \djdigitalemedien\Minify\Middleware\MinifyCss::class,
    // Middleware to minify Javascript
    \djdigitalemedien\Minify\Middleware\MinifyJavascript::class,
    // Middleware to minify Blade
    \djdigitalemedien\Minify\Middleware\MinifyHtml::class,
];
```

You can choose which middleware you want to use. Put all of them if you want to minify html, css, and javascript at the same time.

Register the Middleware (Laravel 11 or newer)
---------------------------------------------

[](#register-the-middleware-laravel-11-or-newer)

In order Minify for Laravel can intercept your request to minify and obfuscate, you need to add the Minify middleware to the `bootstrap/app.php` file:

```
->withMiddleware(function (Middleware $middleware) {
    $middleware->web(append: [
        \djdigitalemedien\Minify\Middleware\MinifyHtml::class,
        \djdigitalemedien\Minify\Middleware\MinifyCss::class,
        \djdigitalemedien\Minify\Middleware\MinifyJavascript::class,
    ]);
})
```

Usage
-----

[](#usage)

This is how you can use Minify for Laravel in your project.

### Minify Asset Files

[](#minify-asset-files)

You must set `true` on `assets_enabled` in the `config/minify.php` file to minify your asset files. For example:

```
"assets_enabled" => env("MINIFY_ASSETS_ENABLED", true),
```

You can minify your asset files by using the `minify()` helper function. This function will minify your asset files and return the minify designed route. In order to work properly, you need to put your asset files in the `resources/js` or `resources/css` directory. For example:

```

```

where `test.css` is located in the `resources/css` directory.

```

```

where `test.js` is located in the `resources/js` directory.

### Automatic Insert Semicolon on Javascript or CSS

[](#automatic-insert-semicolon-on-javascript-or-css)

Use this option if Minify for Laravel makes your javascript or css not working properly. You can enable automatic insert semicolon on javascript or css by setting `true` on `insert_semicolon` in the `config/minify.php` file. For example:

```
"insert_semicolon" => [
    'css' => env("MINIFY_CSS_SEMICOLON", true),
    'js' => env("MINIFY_JS_SEMICOLON", true),
],
```

Caution: this option is experimental. If the code still not working properly, you can disable this option and add semicolon manually to your Javascript or CSS code.

### Skip Minify on Blade

[](#skip-minify-on-blade)

You can skip minify on blade by using attribute `ignore--minify` inside script or style tag. For example:

```

    /* css */

   /* javascript */

```

### Skip Minify when Rendering View

[](#skip-minify-when-rendering-view)

You can skip minify when rendering view by passing `ignore_minify = true` in the view data. For example:

```
return view('welcome', ['ignore_minify' => true]);
```

### Skip Minify by Route

[](#skip-minify-by-route)

You can skip minify by route by adding the route name to the `ignore` array in the `config/minify.php` file. For example:

```
"ignore" => [
    '/admin'
],
```

### Custom Directives Replacement

[](#custom-directives-replacement)

You can replace custom directives by adding the directive name to the `directives` array in the `config/minify.php` file. For example in AlpineJS you can write `@click="function()"`. Unfortunately, Minify for Laravel will remove the `@` symbol. You can replace it by adding `@ => x-on:` to the `directives` array. For example:

```
"directives" => [
    '@' => 'x-on:',
],
```

### Keep Directives

[](#keep-directives)

You can keep directives by adding the directive name to the `keep_directives` array in the `config/minify.php` file. For example when you use `@vite`, you can add `@vite` to the `keep_directives` array. For example:

```
"keep_directives" => [
    '@vite'
],
```

Known Issues
------------

[](#known-issues)

- Minify for Laravel will remove the `@` symbol in the blade file. This will make the blade directive not working properly. You can fix this by adding `@ => x-on:` to the `directives` array in the `config/minify.php` file.
- Does not support for some Javascript framework. You can try experiment by changing the `insert_semicolon` option to `true` or `false` in the `config/minify.php` file.

Contributing
------------

[](#contributing)

If you find an issue, or have a better way to do something, feel free to open an issue, or a pull request. The package is far from perfect, and any help is welcome. There are no formal contribution guidelines, and there should be no contribution too small. All coding styles will be fixed during the pull request by StyleCI. So, don't worry too much about the code style. We'd love to hear from you!

Thanks
------

[](#thanks)

Big thanks to the people who have contributed to this package:

- [@SaeedHeydari](https://github.com/SaeedHeydari)

License
-------

[](#license)

Laravel Minify is licensed under the [MIT license](LICENSE).

Support
-------

[](#support)

If you are having general issues with this package, feel free to contact us on

Report Vulnerability
--------------------

[](#report-vulnerability)

Please read [our security policy](https://github.com/fahlisaputra/laravel-minify/security/policy) for more details.

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity17

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/djdigitalemedien-laravel-minify/health.svg)

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

###  Alternatives

[mustache/mustache

A Mustache implementation in PHP.

3.3k44.6M291](/packages/mustache-mustache)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[whitecube/nova-flexible-content

Flexible Content &amp; Repeater Fields for Laravel Nova.

8053.0M25](/packages/whitecube-nova-flexible-content)[mopa/bootstrap-bundle

Easy integration of twitters bootstrap into symfony2

7042.9M33](/packages/mopa-bootstrap-bundle)[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3871.2M](/packages/limenius-react-bundle)[nicmart/string-template

StringTemplate is a very simple string template engine for php. I've written it to have a thing like sprintf, but with named and nested substutions.

2101.7M30](/packages/nicmart-string-template)

PHPackages © 2026

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