PHPackages                             requtize/assetter - 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. requtize/assetter

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

requtize/assetter
=================

Assets manager for PHP. Allow manage CSS and JS files in website and its dependencies. Also allows refresh cache in browsers by adding revisions of loaded files.

2.0.0(4y ago)145133[1 issues](https://github.com/requtize/assetter/issues)1MITPHPPHP ~7.3 | ~8.0CI failing

Since Oct 24Pushed 4y ago2 watchersCompare

[ Source](https://github.com/requtize/assetter)[ Packagist](https://packagist.org/packages/requtize/assetter)[ Docs](https://github.com/requtize/assetter)[ RSS](/packages/requtize-assetter/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (8)Dependencies (1)Versions (9)Used By (1)

Assetter
========

[](#assetter)

Assets manager for PHP. Allow manage CSS and JS files in website and its dependencies. Also allows refresh cache in browsers by adding revisions of loaded files. Assetter allows you to register namespaces for files paths fo better managing if required.

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

[](#installation)

### Via composer.json

[](#via-composerjson)

```
{
    "require": {
        "requtize/assetter": "^2.0.0"
    }
}
```

### Via Composer CLI

[](#via-composer-cli)

```
composer require requtize/assetter:^2.0.0

```

Table of contents
-----------------

[](#table-of-contents)

- [Basics](#basics)
    1. [Define collection array](#1-define-collection-array)
    2. [Create Assetter object](#2-create-assetter-object)
    3. [Load some libraries](#3-load-some-libraries)
    4. [Show loaded files in document](#4-show-loaded-files-in-document)
- [Register Asset as part of Collection](#register-asset-as-part-of-collection)
- [Namespaces](#namespaces)
    1. [Register namespace](#1-register-namespace)
    2. [Usage registered namespaces](#2-usage-registered-namespaces)
- [LESS ans SCSS Compilers](#less-and-scss-compilers)
    1. [Usage](#1-usage)

Basics
------

[](#basics)

### 1. Define collection array

[](#1-define-collection-array)

First, you have to create array with collection of files.

Here is full indexed array of **one** element in collection.

```
[
    // Basic asset
    'jquery' => [
        'scripts' => [ 'https://code.jquery.com/jquery-3.6.0.min.js' ],
    ],
    // Full asset
    'theme' => [
        'scripts' => [ '/assets/theme/js/script.min.js' ],
        'styles' => [ '/assets/theme/css/theme.min.css' ],
        'require' => [ 'jquery' ],
        'group' => 'head',
        'order' => 100,
        'collection' => 'collection-name'
    ]
]
```

- **scripts** - Stores array of JavaScript files paths (sigle value *(as string)* **NOT ALLOWED**).
- **styles** - Stores array of CSS files paths (sigle value *(as string)* **NOT ALLOWED**).
- **require** - Stores array of names of libraries/assets (elements from collection) that must be loaded with this library. Dependencies.
- **order** - Number of position in loaded files. Lower number = higher in list.
- **group** - Group this library belongs to.
- **collection** - Collection of assets from different modules. Read more on [Register Asset as part of Collection](#register-asset-as-part-of-collection)

### 2. Create Assetter object

[](#2-create-assetter-object)

Now we have to create object of Assetter. To work with Assetter You have to create collection (array) of assets that Assetter can manage.

```
use Requtize\Assetter\Assetter;
use Requtize\Assetter\Collection;

$assetsCollection = [];
$collection = new Collection($assetsCollection);
$assetter = new Assetter($collection);
```

### 3. Require some libraries

[](#3-require-some-libraries)

Now, we can require some libraries. Here we require our `theme` asset, which required also `jquery` asset.

```
$assetter->require('theme');
```

### 4. Show required files in document

[](#4-show-required-files-in-document)

We have required our files. Now it's time to show it in document. To do this, You have to build a collection for group of the assets, and then get the rendered assets.

```
// Build default group
$group = $assetter->build();
// Build "body" group
$group = $assetter->build('body');
// Build "head" group
$group = $assetter->build('head');
```

To render the assets tags use one of the following method using the group.

```
// Returns both CSS and JS files
echo $group->all();
// Returns only CSS files
echo $group->css();
// Returns only JS files
echo $group->js();
```

Register Asset as part of Collection
------------------------------------

[](#register-asset-as-part-of-collection)

Lets say, You have script that manage Dynamic Forms. Script implements plugins that needs to be loaded with it. But plugins have different names and exists in dirrerent parts of app. How to load our script and all of the modules?

Assetter have functionality calles `collections`. Collection is a name of some number of separate assets, that will be loaded as whole, when You require name of the collection.

In example, we have main script, and define two plugins. Now all of these scripts have the same `collection` named `my-collection`:

```
[
    'main-script' => [
        'scripts' => [ '/main-script.js' ],
        'collection' => 'my-collection',
    ],
    'plugin-1' => [
        'scripts' => [ '/plugin-1.js' ],
        'collection' => 'my-collection',
    ],
    'plugin-2' => [
        'scripts' => [ '/plugin-2.js' ],
        'collection' => 'my-collection',
    ],
]
```

Now, You only need to call `require()` with name of the collection:

```
$assetter->require('my-collection');
```

Assetter loads all the assets withing the `my-collection` collection.

Assets will be required in order of declaring, or in order of `require` option defined in each of asset (if defined).

Namespaces
----------

[](#namespaces)

You can define namespaces, that will be applied for every asset path, which use it. Think of namespace (in this case) like some Root path to somethig, like root path to images in your project, or to (more for this) assets path. You can register multiple namespaces, and use multiple namespaces in paths to files for assets. What u need.

### 1. Register namespace

[](#1-register-namespace)

To register namespace, call belowed method. First argument is the name of namespace, you want to register. Second argument is a path to some directory. Followed code shows, how register two namespaces.

```
// Root namespace
$assetter->registerNamespace('{ROOT}', '/web');
// Namespace for global assets
$assetter->registerNamespace('{ASSETS}', '/web/assets');
```

**REMEMBER** - register namespaces before load any asset. Namespaces works only when is needed, so only when you load (or append) any asset. Registered namespaces after load or append won't work.

### 2. Usage registered namespaces

[](#2-usage-registered-namespaces)

When we have registered namespaces, we only now have to add name of namespace to these files path, we need to. Followed example, shows two assets, one works with namespace, second - without.

```
[
    // With namespace
    'with' => [
        'js' => [ '{ASSETS}/jquery-ui.min.js' ],
        'css' => [  '{ASSETS}/themes/smoothness/jquery-ui.css' ]
    ],
    // Without namespace
    'without' => [
        'js' => [ 'http://code.jquery.com/ui/1.11.3/jquery-ui.min.js' ],
        'css' => [ 'http://code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css' ]
    ]
]
```

Namespace can be named as you want, here i provide proposal, you can use any way of name convencion, like: {NS}, \[NS\], %NS, |NS|, -NS, and combine small and big letters as names. But remember to add some special characters. Assetter uses [str\_replace](http://php.net/manual/en/function.str-replace.php) for seach and replace namespaces, so if you named namespace with only letters, some assets paths can be damaged.

How to require CSS in &lt;head&gt; and JS in &lt;body&gt;?
----------------------------------------------------------

[](#how-to-require-css-in-head-and-js-in-body)

This separation of the elements is a common technique, tha allows web browsers renders a fully styled content, without rendering and downloading any JavaScripts at the beginning. Nowadays we require so many JS libs in our websites, all those files must be downloaded by browser at the place of occurence. Moving those files at the end of the body speeds up the page load.

To achive that, You have to define the `head` and the `body` part of the asset, and then mix them together into one, like this:

```
[
    // This goes to HEAD, only CSS
    'bootstrap.head' => [
        'styles' => [ 'bootstrap.min.css' ],
        'group' => 'head',
    ],
    // This goes to BODY, all JS
    'bootstrap.body' => [
        'scripts' => [ 'bootstrap.min.js' ],
        'group' => 'body',
    ],
    // This mix it up together
    'bootstrap' => [
        'require' => [ 'bootstrap.head', 'bootstrap.body' ],
    ],
]
```

That defined asset You have to only require using the mixed name `bootstrap`. Assetter take care of the rest of the assets, and build them into proper defined group in building time.

```
$assetter->require('bootstrap');
```

Last part, you have to only build assets separate for HEAD and for the BODY.

```

        build('body')->all(); ?>

        build('head')->all(); ?>

```

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 80.4% 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 ~328 days

Recently: every ~358 days

Total

8

Last Release

1602d ago

Major Versions

0.1.0 → 1.0.02016-04-26

1.2.1 → 2.0.02022-02-08

PHP version history (4 changes)0.1.0PHP &gt;=5.4.0

1.0.1PHP ~5.5 || ^7.0

1.0.2PHP ~5.5 || ~7.0

2.0.0PHP ~7.3 | ~8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/6198c3bc2e2b37d339cc79893c9dd0d100c4443f56361d527bf5306acf2cbe68?d=identicon)[requtize](/maintainers/requtize)

---

Top Contributors

[![Mediaessence](https://avatars.githubusercontent.com/u/262103130?v=4)](https://github.com/Mediaessence "Mediaessence (37 commits)")[![adambanaszkiewicz](https://avatars.githubusercontent.com/u/7622472?v=4)](https://github.com/adambanaszkiewicz "adambanaszkiewicz (9 commits)")

---

Tags

assetsassets-managementcssdependency-managerjavascriptlessloadersassmanagerassetsassetfiles-manager

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/requtize-assetter/health.svg)

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

###  Alternatives

[stolz/assets

An ultra-simple-to-use assets management library

289527.4k8](/packages/stolz-assets)[rumenx/php-assets

Framework-agnostic PHP package to manage frontend assets in the backend. Works with plain PHP, Laravel, Symfony, and any PHP framework.

1043.3k](/packages/rumenx-php-assets)[corneltek/assetkit

High performance asset manager.

531.4k3](/packages/corneltek-assetkit)[fisharebest/laravel-assets

Asset management for Laravel

208.1k](/packages/fisharebest-laravel-assets)[mmanos/laravel-casset

An asset management package for Laravel 4.

102.6k](/packages/mmanos-laravel-casset)

PHPackages © 2026

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