PHPackages                             debjyotikar001/asset-optimise - 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. debjyotikar001/asset-optimise

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

debjyotikar001/asset-optimise
=============================

A Laravel package that optimizes front-end assets by minifying HTML, CSS, and JavaScript, enhancing page load speeds and save bandwidth.

V4.0.1(3mo ago)1313MITPHPPHP &gt;=8.0

Since Sep 17Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/debjyotikar001/asset-optimise)[ Packagist](https://packagist.org/packages/debjyotikar001/asset-optimise)[ RSS](/packages/debjyotikar001-asset-optimise/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (3)Versions (10)Used By (0)

Asset Optimise for Laravel
==========================

[](#asset-optimise-for-laravel)

Asset Optimise is a powerful and lightweight Laravel package designed to enhance the performance of your web applications by optimizing front-end assets. This package automatically minifies HTML, CSS, and JavaScript code to reduce file sizes, improve page load times and save bandwidth.

Key Features:
-------------

[](#key-features)

1. Minifies HTML, CSS, and JavaScript for faster loading. [Read More...](#enable)
2. Configurable to skip minification for [inline CSS](#skip-inline-css), [inline JavaScript](#skip-inline-javascript) and [HTML comments](#skip-html-comments).
3. Supports excluding specific sections of code from being minified using custom HTML comments. [Read More...](#skip-specific-sections-of-code)
4. Supports excluding specific routes urls paths from being minified. [Read More...](#skip-or-ignore-specific-routes-urls)
5. Configurable to skip minification for specific application Environment. [Read More...](#allowed-environments)
6. Easy integration with Laravel's middleware system. [Read More...](#register-the-middleware)
7. Supports Email (HTML, CSS, and JavaScript) minification. [Read More...](#enable-email-optimise)
8. JavaScript encryption with domains support for more security. [Read More...](#javascript-encrypt-domains)
9. Support multiple assets (CSS or JavaScript) merge and minify. [Read More...](#merge-and-minify-multiple-assets-css-or-javascript)
10. Support asset (CSS or JavaScript) minification. [Read More...](#minify-asset-css-or-javascript)
11. Provides an Artisan command to clear generated minified assets for storage management. [Read More...](#clear-minified-assets)
12. Extensible for future updates, including image compression and CDN integration.

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

[](#installation)

Asset Optimise for Laravel requires PHP 8.0 or higher. This particular version supports Laravel 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 debjyotikar001/asset-optimise
```

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

[](#configuration)

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

```
php artisan vendor:publish --provider="Debjyotikar001\AssetOptimise\AssetOptimiseServiceProvider"
```

This will create a `config/assetoptimise.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.

Register the Middleware
-----------------------

[](#register-the-middleware)

In order to add asset optimization functionality in Laravel, you need to add the Minifier middleware.

### (Laravel 10 or older)

[](#laravel-10-or-older)

In `app/Http/Kernel.php` file:

```
protected $middleware = [
  // other middleware
  \Debjyotikar001\AssetOptimise\Middleware\Minifier::class,
];
```

or

```
protected $middleware = [
  // other middleware
  'assetOptimise',
];
```

You can use the middleware class or middleware alias `assetOptimise` in web middleware or route.

### (Laravel 11 or newer)

[](#laravel-11-or-newer)

In `bootstrap/app.php` file:

```
->withMiddleware(function (Middleware $middleware) {
  $middleware->web(append: [
    // other middleware
    \Debjyotikar001\AssetOptimise\Middleware\Minifier::class,
  ]);
})
```

or

```
->withMiddleware(function (Middleware $middleware) {
  $middleware->web(append: [
    // other middleware
    'assetOptimise',
  ]);
})
```

You can use the middleware class or middleware alias `assetOptimise` in web middleware or route.

Usage
-----

[](#usage)

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

### Enable

[](#enable)

You must set `true` on `enabled` in the `config/assetoptimise.php` file enable asset optimization functionality. For example:

```
'enabled' => env('ASSETOPTIMISE_ENABLED', true),
```

### Allowed Environments

[](#allowed-environments)

If you want to disable it in specific environments such as during local development or testing to simplify debugging. Then set environments values in a comma (`,`) separated string in the `config/assetoptimise.php` file, default `local,production,staging`. For example:

```
'allowed_envs' => env('ASSETOPTIMISE_ALLOWED_ENVS', 'local,production,staging'),
```

### Skip specific sections of code

[](#skip-specific-sections-of-code)

If you want to skip specific sections of code from being minified using `\ ... ` HTML comments. This sections supports HTML, CSS and JavaScript code. For example:

```

  /* Don't optimise this CSS code */
  h1 {
    color: black;
    font-size: 40px;
  }

  p {
    color: red;
    font-size: 24px;
  }

Asset Optimise
Don't optimise this HTML code

  // Don't optimise this JavaScript code
  alert("Asset Optimise: Don't optimise this JavaScript code");

```

### Skip Inline CSS

[](#skip-inline-css)

If you want to skip inline CSS (within `` tags in your HTML) optimization. Then set `true` on `skip_css` in the `config/assetoptimise.php` file, default `false`. For example:

```
'skip_css' => env('ASSETOPTIMISE_SKIP_CSS', true),
```

### Skip Inline JavaScript

[](#skip-inline-javascript)

If you want to skip inline JavaScript (within `` tags in your HTML) optimization. Then set `true` on `skip_js` in the `config/assetoptimise.php` file, default `false`. For example:

```
'skip_js' => env('ASSETOPTIMISE_SKIP_JS', true),
```

### Skip HTML Comments

[](#skip-html-comments)

If you want to skip all HTML comments from the output. Then set `true` on `skip_comment` in the `config/assetoptimise.php` file, default `false`. For example:

```
'skip_comment' => env('ASSETOPTIMISE_SKIP_COMMENT', true),
```

### Skip or Ignore specific Routes Urls

[](#skip-or-ignore-specific-routes-urls)

If you want to skip or ignore specific routes urls, then you have to set paths in the `config/assetoptimise.php` file. You can use '\*' as wildcard. For example:

```
'skip_urls' => [
    '/',
    'about',
    'user/*',
    '*_dashboard',
    '*/download/*',
  ],
```

#### Example URLs:

[](#example-urls)

- `/`: Home URL will be excluded from minification.
- `about`: This exact URL will be excluded from minification.
- `user/*`: Any URL starting with `user/` (like `user/profile`, `user/settings`) will be excluded.
- `*_dashboard`: Any URL ending with `_dashboard` (like `admin_dashboard`, `user_dashboard`) will be excluded.
- `*/download/*`: Any URL has `download` (like `pdf/download/001`, `image/download/debjyotikar001`) will be excluded.

### Enable Email Optimise

[](#enable-email-optimise)

You must set `true` on `email_enabled` in the `config/assetoptimise.php` file to enable asset optimization functionality for emails. For example:

```
'email_enabled' => env('ASSETOPTIMISE_EMAIL_ENABLED', true),
```

### JavaScript Encrypt Domains

[](#javascript-encrypt-domains)

Add domains in the `config/assetoptimise.php` file for more security, then encrypted JavaScript code will only work on those domains. For example:

```
'js_encrypt_domains' => [
    'example.com',
    'example1.com',
    'example2.com',
  ],
```

#### Please Note:

[](#please-note)

- JavaScript encryption may slow down application performance.
- Large scripts can take longer to process.
- This may cause an error if the code is not written properly. Please use with caution!
- Although this can provide a high security level, a potentially thief can try to de-obfuscate and reach a closer code to the original one due to the public and open architecture of JavaScript.
- So it's not recommended to use this to protect sensitive information.

### Merge and Minify multiple assets (CSS or JavaScript)

[](#merge-and-minify-multiple-assets-css-or-javascript)

You can use `minifyAssets()` helper function that allows you to merge and minify your multiple CSS or JavaScript files. This function will handle both `public` and `resources` directories, storing the final output file in your storage folder for optimized use. It reduces the number of HTTP requests and speeds up the loading of assets.

#### How It Works

[](#how-it-works)

The `minifyAssets()` helper function accepts three parameters:

- **File paths (array):** A list of CSS or JavaScript files that you want to merge and minify. The paths can be from both the `public` and `resources` directories.
- **File type (string):** Either `css` or `js`, specifying the type of files being merged.
- **Options (array, Optional):** This options array accepts several data:
    - **JavaScript encrypt (`'jsEncrypt'`):** Whether to encrypt JavaScript for extra security. Default is `false`.
    - **Cache time (`'ttl'`):** Time after which the merged file will be refreshed. Default is `7` days. [Learn More](#cache-time)
    - **Output File name (`'name'`):** The name of the final output file (without extension) that will be generated and stored. Default auto-generated File name.
    - **Version (`'version'`):** The version can be number (like `2`, `1.0.1`) or string (like `beta`, `testing`). Or it can be null.

##### Cache Time

[](#cache-time)

Cache time can be in `minutes`, `hours`, `days`, `years`.

- **Format:** `{number}{unit}`
- **Units:**
    - `m` = minutes (max `1440` → `1` day)
    - `h` = hours (max `720` → `30` days)
    - `d` = days (max `365` → `1` year)
    - `y` = years (max `5` → `5` years)
- **Example:** `7d` → regenerates every `7` days

#### Example (CSS)

[](#example-css)

```

```

The file paths can be from both the `public` and `resources/css` directories. It returns `merged-css_v101.min.css` file url.

#### Example (JS)

[](#example-js)

```

```

The file paths can be from both the `public` and `resources/js` directories. It returns `merged-js_beta.min.js` file url. And it also encrypt the JavaScript code.

### Clear Minified Assets

[](#clear-minified-assets)

Asset Optimise stores generated and merged minified assets inside the `storage/app/public/minified` directory. Over time, older or unused minified files may accumulate and increase storage usage. To clean up these files, Asset Optimise provides an Artisan command that allows you to remove minified assets safely.

#### Clear All Minified Assets

[](#clear-all-minified-assets)

This command removes all generated minified assets (both CSS and JavaScript):

```
php artisan asset-optimise:clear-minified
```

#### Clear Only CSS Minified Assets

[](#clear-only-css-minified-assets)

If you want to remove only minified CSS files:

```
php artisan asset-optimise:clear-minified css
```

#### Clear Only JavaScript Minified Assets

[](#clear-only-javascript-minified-assets)

If you want to remove only minified JavaScript files:

```
php artisan asset-optimise:clear-minified js
```

This command is useful for periodic cleanup, storage management, or when deploying new versions of your assets.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Contributions are welcome! Please see [CONTRIBUTING](CONTRIBUTING.md) for details on how to get started.

License
-------

[](#license)

Asset Optimise is licensed under the [MIT license](LICENSE).

Credits
-------

[](#credits)

This package uses the [hexydec/htmldoc](https://github.com/hexydec/htmldoc) library for HTML, CSS and JavaScript minification.

Support
-------

[](#support)

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

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance82

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

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 ~63 days

Recently: every ~90 days

Total

9

Last Release

91d ago

Major Versions

V1.0.0 → V2.0.02024-09-21

V2.2.1 → V3.0.02025-03-16

V3.0.1 → V4.0.02025-11-17

### Community

Maintainers

![](https://www.gravatar.com/avatar/181fa9558a8a9dce047eecb9f4a1b6c60b21a0fad6d3dceaf303bf9fcfb396b7?d=identicon)[debjyotikar001](/maintainers/debjyotikar001)

---

Top Contributors

[![debjyotikar001](https://avatars.githubusercontent.com/u/100521307?v=4)](https://github.com/debjyotikar001 "debjyotikar001 (14 commits)")

---

Tags

laraveljavascriptcsscompressionhtmloptimizationminificationasset

### Embed Badge

![Health badge](/badges/debjyotikar001-asset-optimise/health.svg)

```
[![Health](https://phpackages.com/badges/debjyotikar001-asset-optimise/health.svg)](https://phpackages.com/packages/debjyotikar001-asset-optimise)
```

###  Alternatives

[stolz/assets

An ultra-simple-to-use assets management library

296519.2k8](/packages/stolz-assets)[unisharp/laravel-ckeditor

JavaScript WYSIWYG web text editor (for laravel).

377762.3k5](/packages/unisharp-laravel-ckeditor)[mmanos/laravel-casset

An asset management package for Laravel 4.

102.6k](/packages/mmanos-laravel-casset)[dotsunited/bundlefu

BundleFu is a PHP 5.3+ library which bundles multiple css/javascript files into a big package and sends it out at once

7028.5k3](/packages/dotsunited-bundlefu)[fisharebest/laravel-assets

Asset management for Laravel

208.1k](/packages/fisharebest-laravel-assets)[bissolli/php-css-js-minifier

A PHP Class to merge and minify CSS and JavaScript files.

102.8k4](/packages/bissolli-php-css-js-minifier)

PHPackages © 2026

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