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

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

fahlisaputra/laravel-minify
===========================

Minify your blade views, html, css and obfuscate js files on the fly. Lightweight minifier for your Laravel project.

v1.2.3(10mo ago)150157.0k—4.3%24[10 issues](https://github.com/fahlisaputra/laravel-minify/issues)[1 PRs](https://github.com/fahlisaputra/laravel-minify/pulls)1MITPHPPHP ^7.2.5 || ^8.0 || ^8.1 || ^8.2 || ^8.3 || ^8.4

Since Jul 19Pushed 5mo ago4 watchersCompare

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

READMEChangelog (10)Dependencies (3)Versions (16)Used By (1)

[![Logo](assets/minify_logo.svg)](assets/minify_logo.svg)

Minify for Laravel
==================

[](#minify-for-laravel)

Minify for Laravel is a package for minifying and obfuscating Javascript, CSS, HTML and Blade views. It runs automatically when you load a page or view. Increase your website performance on page load and save bandwidth. Obfuscate your Javascript to protect your code from being stolen.

[![Latest Stable Version](https://camo.githubusercontent.com/538f91d95dddb4e5706926ac698c55f3146ed6c12881adf793832aa8ef91108e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6661686c69736170757472612f6c61726176656c2d6d696e696679)](https://packagist.org/packages/fahlisaputra/laravel-minify)[![Total Downloads](https://camo.githubusercontent.com/ae21c88500ad93aa66409283558ac339a15c13d933101789e8d05674c5e18ac7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6661686c69736170757472612f6c61726176656c2d6d696e696679)](https://packagist.org/packages/fahlisaputra/laravel-minify)[![License](https://camo.githubusercontent.com/86d81f2b85d00c2fd523f0aa8043fc54d5bfa6829966e8cd32c8b46ce732e948/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6661686c69736170757472612f6c61726176656c2d6d696e696679)](https://packagist.org/packages/fahlisaputra/laravel-minify)[![StyleCI](https://camo.githubusercontent.com/1b0820f038350e4b09a3a1c4ec7128d273a516cd3e7af696f8c17b599dcbf816/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3636373836303330392f736869656c643f6272616e63683d6d61696e)](https://github.styleci.io/repos/667860309?branch=main)

Comparison
----------

[](#comparison)

This image shows the difference in size between the original file and the minified file of default welcome.blade.php Laravel. The original file size is 28.7 KB and the minified file size is 25.7 KB. The minified file size is 10% smaller than the original file size.

[![Logo](assets/comparison.png)](assets/comparison.png)

If you minify all your asset files, you can save up to 50% of your bandwidth. This will make your website load faster and save your hosting cost. When you have big files, the difference in size will be even greater.

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

[](#installation)

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

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

```
composer require fahlisaputra/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="Fahlisaputra\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 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: [
        \Fahlisaputra\Minify\Middleware\MinifyHtml::class,
        \Fahlisaputra\Minify\Middleware\MinifyCss::class,
        \Fahlisaputra\Minify\Middleware\MinifyJavascript::class,
    ]);
})
```

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
    \Fahlisaputra\Minify\Middleware\MinifyCss::class,
    // Middleware to minify Javascript
    \Fahlisaputra\Minify\Middleware\MinifyJavascript::class,
    // Middleware to minify Blade
    \Fahlisaputra\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.

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. If the option set to `false` the route will not registered from service provider. 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. For example:

```

```

```

```

You can modify the assets storage directory path by setting `assets_path` in the `config/minify.php` file. By default, the assets storage directory path is `resources`. For example:

```
"assets_storage" => env("MINIFY_ASSETS_STORAGE", 'resources'),
```

In order to minimize the security risk, the root storage directory is hidden from the public. For the example, you set the `assets_storage` to `storage/app/private/assets` and you want to access the file `test.css` in the `storage/app/private/assets/test.css`. You can use the `minify()` helper function like this:

```

```

The `minify()` helper function will automatically search the file in the `storage/app/private/assets` directory. The result on the browser will be like this:

```

```

The `/storage/app/private/assets` directory is hidden from the public.

### 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 LD+JSON Script Minification

[](#skip-ldjson-script-minification)

You can configure Minify for Laravel to automatically skip minification of `` tags by setting `skip_ld_json` to `true` in the `config/minify.php` file. This is enabled by default to preserve structured data for SEO purposes. For example:

```
"skip_ld_json" => env("MINIFY_SKIP_LD_JSON", true),
```

When enabled, scripts like this will not be minified:

```

{
  "@context": "https://schema.org",
  "@type": "Organization",
  "name": "My Company",
  "url": "https://example.com"
}

```

### 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!

Contributors
------------

[](#contributors)

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

[ ![](https://camo.githubusercontent.com/104a305234b0e73ef7c72db61ec68153cda430157e77d6bab94e6b616a275eb2/68747470733a2f2f636f6e747269622e726f636b732f696d6167653f7265706f3d6661686c69736170757472612f6c61726176656c2d6d696e696679)](https://github.com/fahlisaputra/laravel-minify/graphs/contributors)and [@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

55

—

FairBetter than 98% of packages

Maintenance61

Regular maintenance activity

Popularity51

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 87.8% 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 ~79 days

Recently: every ~120 days

Total

10

Last Release

316d ago

PHP version history (3 changes)v1.0.0PHP ^7.2.5 || ^8.0

v1.1.5PHP ^7.2.5 || ^8.0 || ^8.1 || ^8.2 || ^8.3

v1.2.2PHP ^7.2.5 || ^8.0 || ^8.1 || ^8.2 || ^8.3 || ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/6e8244485a96b63cbcad5d06edeab48ff675d3b1d6c1c90c1efb89ba51cb0980?d=identicon)[fahlisaputra](/maintainers/fahlisaputra)

---

Top Contributors

[![fahlisaputra](https://avatars.githubusercontent.com/u/56981940?v=4)](https://github.com/fahlisaputra "fahlisaputra (65 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (6 commits)")[![oriceon](https://avatars.githubusercontent.com/u/358823?v=4)](https://github.com/oriceon "oriceon (1 commits)")[![scybulski](https://avatars.githubusercontent.com/u/10341108?v=4)](https://github.com/scybulski "scybulski (1 commits)")[![StephaneBour](https://avatars.githubusercontent.com/u/15020891?v=4)](https://github.com/StephaneBour "StephaneBour (1 commits)")

---

Tags

hacktoberfestjs-obfuscatorlaravelminifierminifyobfuscatorlaravelhtml minifiercss-minifierjs-minifierjs-obfuscate

### Embed Badge

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

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

###  Alternatives

[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[rcrowe/twigbridge

Adds the power of Twig to Laravel

9105.9M50](/packages/rcrowe-twigbridge)[tightenco/jigsaw

Simple static sites with Laravel's Blade.

2.2k438.5k29](/packages/tightenco-jigsaw)[moonshine/moonshine

Laravel administration panel

1.3k217.1k59](/packages/moonshine-moonshine)[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.

44643.1k1](/packages/pressbooks-pressbooks)[torchlight/torchlight-laravel

A Laravel Client for Torchlight, the syntax highlighting API.

120452.8k11](/packages/torchlight-torchlight-laravel)

PHPackages © 2026

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