PHPackages                             jbzoo/assets - 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. jbzoo/assets

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

jbzoo/assets
============

Manage any asset files (js, css, less) and their depending + compressing and merging

7.1.1(9mo ago)555.7k1MITPHPPHP ^8.2CI passing

Since Mar 2Pushed 9mo ago3 watchersCompare

[ Source](https://github.com/JBZoo/Assets)[ Packagist](https://packagist.org/packages/jbzoo/assets)[ RSS](/packages/jbzoo-assets/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (6)Versions (28)Used By (1)

JBZoo / Assets
==============

[](#jbzoo--assets)

[![CI](https://github.com/JBZoo/Assets/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/JBZoo/Assets/actions/workflows/main.yml?query=branch%3Amaster) [![Coverage Status](https://camo.githubusercontent.com/671f99a1f2cc9b86990ccc3d35ec9a824eae6f65fd0c98fc13ee4135342fe071/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f4a425a6f6f2f4173736574732f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/JBZoo/Assets?branch=master) [![Psalm Coverage](https://camo.githubusercontent.com/88e61bf5246c2cfc1c97d30caf45b810ec3798da1abf752185ffa0c688157954/68747470733a2f2f73686570686572642e6465762f6769746875622f4a425a6f6f2f4173736574732f636f7665726167652e737667)](https://shepherd.dev/github/JBZoo/Assets) [![Psalm Level](https://camo.githubusercontent.com/1d6c06146b08eadd4f5ba4fc4ed570b9ec982f782146abf2f2c94cc75b923292/68747470733a2f2f73686570686572642e6465762f6769746875622f4a425a6f6f2f4173736574732f6c6576656c2e737667)](https://shepherd.dev/github/JBZoo/Assets) [![CodeFactor](https://camo.githubusercontent.com/c437f11ce24f566a950b195cd5dfbaed341837c3164d72a9564fb8c89b89ad96/68747470733a2f2f7777772e636f6465666163746f722e696f2f7265706f7369746f72792f6769746875622f6a627a6f6f2f6173736574732f6261646765)](https://www.codefactor.io/repository/github/jbzoo/assets/issues)[![Stable Version](https://camo.githubusercontent.com/711e06eebfa5a8a2ea6ab99a4d24306608ba9bae3d6c7a6b157f29aa391a05df/68747470733a2f2f706f7365722e707567782e6f72672f6a627a6f6f2f6173736574732f76657273696f6e)](https://packagist.org/packages/jbzoo/assets/) [![Total Downloads](https://camo.githubusercontent.com/31fd69f92c4f7f7c2b4040dca13a94fa33b3efc1991bce5945bc0b72b19bc019/68747470733a2f2f706f7365722e707567782e6f72672f6a627a6f6f2f6173736574732f646f776e6c6f616473)](https://packagist.org/packages/jbzoo/assets/stats) [![Dependents](https://camo.githubusercontent.com/296f2457a7fdb4e1f8e495238350ec752c44bfba8bbce6b42fd7b3c6442832d0/68747470733a2f2f706f7365722e707567782e6f72672f6a627a6f6f2f6173736574732f646570656e64656e7473)](https://packagist.org/packages/jbzoo/assets/dependents?order_by=downloads) [![GitHub License](https://camo.githubusercontent.com/5bb48c1bb041158dfc15197a6df2cf70195808bf6cc9fd5cfcf6b925ab21a61b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a627a6f6f2f617373657473)](https://github.com/JBZoo/Assets/blob/master/LICENSE)

A PHP library for managing asset files (JavaScript, CSS, LESS, JSX) with dependency resolution, compression, and merging capabilities. The library provides automatic type detection, dependency management, and a flexible build system for modern web applications.

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

[](#installation)

```
composer require jbzoo/assets
```

Quick Start
-----------

[](#quick-start)

```
use JBZoo\Assets\Manager;
use JBZoo\Path\Path;

// Initialize path resolver and asset manager
$path = new Path();
$path->set('assets', '/path/to/your/assets');

$manager = new Manager($path);

// Register and queue assets
$manager
    ->register('jquery', 'assets/js/jquery.js')
    ->register('bootstrap-css', 'assets/css/bootstrap.css')
    ->register('app', 'assets/js/app.js', ['jquery']) // depends on jquery
    ->add('bootstrap-css')
    ->add('app');

// Build assets with dependency resolution
$assets = $manager->build();

// Output: Array with organized asset types
// $assets['js'] contains JavaScript files
// $assets['css'] contains CSS files
```

Supported Asset Types
---------------------

[](#supported-asset-types)

### File-based Assets

[](#file-based-assets)

The library automatically detects asset types by file extension:

```
// JavaScript files (.js)
$manager->register('script', 'assets/js/script.js');

// CSS files (.css)
$manager->register('styles', 'assets/css/styles.css');

// LESS files (.less)
$manager->register('theme', 'assets/less/theme.less');

// JSX files (.jsx)
$manager->register('component', 'assets/jsx/component.jsx');
```

### Code-based Assets

[](#code-based-assets)

Include inline code directly:

```
use JBZoo\Assets\Asset\AbstractAsset;

// Inline CSS
$manager->register('inline-css', 'div { color: red; }', [], [
    'type' => AbstractAsset::TYPE_CSS_CODE
]);

// Inline JavaScript
$manager->register('inline-js', 'console.log("Hello World");', [], [
    'type' => AbstractAsset::TYPE_JS_CODE
]);

// Code with HTML tags (automatically stripped)
$manager->register('styled', 'body { margin: 0; }', [], [
    'type' => AbstractAsset::TYPE_CSS_CODE
]);
```

### External Assets

[](#external-assets)

```
// CDN resources
$manager->register('jquery-cdn', 'https://code.jquery.com/jquery-3.6.0.min.js');

// External stylesheets
$manager->register('bootstrap-cdn', 'https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css');
```

### Callback Assets

[](#callback-assets)

Execute custom logic during the build process:

```
// Simple callback
$manager->register('analytics', function() {
    return 'ga("send", "pageview");';
});

// Multiple callbacks in collection
$manager->add('init-scripts', [
    function() { return 'console.log("Script 1");'; },
    function() { return 'console.log("Script 2");'; },
    function() { return 'console.log("Done");'; }
]);
```

Dependency Management
---------------------

[](#dependency-management)

### Basic Dependencies

[](#basic-dependencies)

```
// jQuery must load before Bootstrap JavaScript
$manager
    ->register('jquery', 'assets/js/jquery.js')
    ->register('bootstrap-js', 'assets/js/bootstrap.js', ['jquery'])
    ->add('bootstrap-js'); // jQuery will be included automatically
```

### Complex Dependency Trees

[](#complex-dependency-trees)

```
$manager
    ->register('utilities', 'assets/js/utils.js')
    ->register('jquery', 'assets/js/jquery.js')
    ->register('plugin', 'assets/js/plugin.js', ['jquery', 'utilities'])
    ->register('app', 'assets/js/app.js', ['plugin'])
    ->add('app');

// Build order: utilities, jquery, plugin, app
```

### Circular Dependency Detection

[](#circular-dependency-detection)

```
try {
    $manager
        ->register('a', 'a.js', ['b'])
        ->register('b', 'b.js', ['a']) // Circular dependency
        ->add('a');

    $manager->build(); // Throws exception
} catch (\JBZoo\Assets\Exception $e) {
    echo "Circular dependency detected: " . $e->getMessage();
}
```

Path Resolution
---------------

[](#path-resolution)

### Virtual Paths

[](#virtual-paths)

```
$path = new Path();
$path->set('assets', '/var/www/assets');
$path->set('vendor', '/var/www/vendor');

$manager = new Manager($path);

// Use virtual paths
$manager->register('app', 'assets:js/app.js');        // Resolves to /var/www/assets/js/app.js
$manager->register('lib', 'vendor:lib/script.js');    // Resolves to /var/www/vendor/lib/script.js
```

### Relative and Absolute Paths

[](#relative-and-absolute-paths)

```
// Relative to current working directory
$manager->register('local', 'js/local.js');

// Absolute path
$manager->register('system', '/usr/share/js/system.js');
```

Configuration Options
---------------------

[](#configuration-options)

### Debug Mode

[](#debug-mode)

```
$manager = new Manager($path, ['debug' => true]);

// Or set later
$manager->setParam('debug', true);
```

### Strict Mode

[](#strict-mode)

```
$manager = new Manager($path, ['strict_mode' => true]);

// Throws exceptions for missing files
$manager->register('missing', 'assets/js/missing.js');
$manager->add('missing');
$manager->build(); // Exception thrown
```

### LESS Compilation Options

[](#less-compilation-options)

```
$manager = new Manager($path, [
    'less' => [
        'compress' => true,
        'sourceMap' => false
    ]
]);
```

Building and Output
-------------------

[](#building-and-output)

### Basic Build

[](#basic-build)

```
$assets = $manager->build();

// Result structure:
[
    'js'         => ['path/to/script1.js', 'path/to/script2.js'],
    'js_code'    => ['console.log("inline");'],
    'jsx'        => ['path/to/component.jsx'],
    'jsx_code'   => ['ReactDOM.render(...);'],
    'css'        => ['path/to/styles.css'],
    'css_code'   => ['body { margin: 0; }'],
    'callback'   => [42, 'result', ...]  // Callback return values
]
```

### Processing Build Results

[](#processing-build-results)

```
$assets = $manager->build();

// Generate HTML tags
foreach ($assets['css'] as $cssFile) {
    echo '' . PHP_EOL;
}

foreach ($assets['js'] as $jsFile) {
    echo '' . PHP_EOL;
}

// Include inline styles
if (!empty($assets['css_code'])) {
    echo '' . implode("\n", $assets['css_code']) . '';
}

// Include inline scripts
if (!empty($assets['js_code'])) {
    echo '' . implode("\n", $assets['js_code']) . '';
}
```

Asset Collections
-----------------

[](#asset-collections)

### Grouping Related Assets

[](#grouping-related-assets)

```
// Register a collection of related assets
$manager->add('ui-components', [
    'assets/css/buttons.css',
    'assets/css/modals.css',
    'assets/js/components.js'
]);
```

### Managing Asset Queues

[](#managing-asset-queues)

```
// Add assets to queue
$manager
    ->add('jquery')
    ->add('bootstrap')
    ->add('app');

// Remove from queue (but keep registered)
$manager->remove('bootstrap');

// Unregister completely
$manager->unregister('app');
```

Advanced Usage
--------------

[](#advanced-usage)

### Custom Asset Types

[](#custom-asset-types)

```
// Register custom asset type
$manager->getFactory()->registerType('custom', CustomAssetClass::class);

// Use custom type
$manager->register('special', 'data', [], ['type' => 'custom']);
```

### Conditional Asset Loading

[](#conditional-asset-loading)

```
$isProduction = $_ENV['APP_ENV'] === 'production';

if ($isProduction) {
    $manager->register('analytics', 'assets/js/analytics.min.js');
} else {
    $manager->register('debug-tools', 'assets/js/debug.js');
}
```

### Asset Preprocessing

[](#asset-preprocessing)

```
$manager->register('processed', function() use ($dataProcessor) {
    $data = $dataProcessor->compile();
    return "window.appData = " . json_encode($data) . ";";
});
```

Error Handling
--------------

[](#error-handling)

```
try {
    $manager
        ->register('app', 'missing-file.js')
        ->add('app');

    $assets = $manager->build();
} catch (\JBZoo\Assets\Exception $e) {
    // Handle missing files, circular dependencies, etc.
    error_log("Asset error: " . $e->getMessage());
}
```

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

[](#requirements)

- PHP 8.2 or higher
- JBZoo Utils package
- JBZoo Path package
- JBZoo Data package
- JBZoo Less package (for LESS file support)

Testing
-------

[](#testing)

```
# Run all tests
make test
make codestyle
```

License
-------

[](#license)

MIT

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance58

Moderate activity, may be stable

Popularity31

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity86

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 89.1% 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 ~134 days

Recently: every ~355 days

Total

27

Last Release

279d ago

Major Versions

1.2.1 → 2.0.02019-11-24

2.0.0 → 3.0.02020-02-19

3.0.0 → 4.0.02020-07-14

4.3.2 → 5.0.02022-06-06

5.0.0 → 7.0.02023-07-09

PHP version history (7 changes)1.0.0PHP &gt;=5.4

2.0.0PHP &gt;=7.1

4.0.0PHP &gt;=7.2

4.0.1PHP ^7.2

5.0.0PHP &gt;=7.4

7.0.0PHP ^8.1

7.1.1PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/75e6de2785f6d099699f430ff58404af4fc0e83060d2953028c9664a54704a5f?d=identicon)[smetdenis](/maintainers/smetdenis)

---

Top Contributors

[![SmetDenis](https://avatars.githubusercontent.com/u/1118678?v=4)](https://github.com/SmetDenis "SmetDenis (41 commits)")[![Cheren](https://avatars.githubusercontent.com/u/4447959?v=4)](https://github.com/Cheren "Cheren (5 commits)")

---

Tags

assetsassets-managementcssjavascriptjbzoolessjavascriptcssJScompresslessassets

### Embed Badge

![Health badge](/badges/jbzoo-assets/health.svg)

```
[![Health](https://phpackages.com/badges/jbzoo-assets/health.svg)](https://phpackages.com/packages/jbzoo-assets)
```

###  Alternatives

[matthiasmullie/minify

CSS &amp; JavaScript minifier, in PHP. Removes whitespace, strips comments, combines files (incl. @import statements and small assets in CSS files), and optimizes/shortens a few common programming patterns.

2.0k33.1M462](/packages/matthiasmullie-minify)[stolz/assets

An ultra-simple-to-use assets management library

289531.9k8](/packages/stolz-assets)[sensiolabs/minify-bundle

Assets Minifier (CSS, JS) for Symfony &amp; Minify integration in Asset Mapper

57155.0k3](/packages/sensiolabs-minify-bundle)[janmarek/webloader

Tool for loading or deploying CSS and JS files into web pages

114517.9k14](/packages/janmarek-webloader)[efficiently/larasset

Larasset is a library for Laravel 5 which manage assets in an easy way.

684.8k](/packages/efficiently-larasset)[ishanvyas22/asset-mix

Asset Mix plugin for CakePHP

3476.9k2](/packages/ishanvyas22-asset-mix)

PHPackages © 2026

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