PHPackages                             aelora/js-css-queue - 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. aelora/js-css-queue

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

aelora/js-css-queue
===================

PHP package for queueing JavaScript and CSS files

023[1 issues](https://github.com/RyanNutt/jscssqueue/issues)PHP

Since Oct 21Pushed 6y agoCompare

[ Source](https://github.com/RyanNutt/jscssqueue)[ Packagist](https://packagist.org/packages/aelora/js-css-queue)[ RSS](/packages/aelora-js-css-queue/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (1)Used By (0)

JavaScript &amp; CSS Queue for PHP
----------------------------------

[](#javascript--css-queue-for-php)

PHP package for registering and enqueuing JavaScript and CSS files.

### Installation

[](#installation)

```
composer require aelora/js-css-queue

```

### Usage

[](#usage)

Both classes have the same set of methods. In pretty much all cases an example call to `\Aelora\JS::method` below has a buddy `\Aelora\CSS::method` in the `CSS` class.

#### Registering Files

[](#registering-files)

```
\Aelora\JS::register($url, $name='', $version=false, $dependencies=[], $attributes=[]);
```

```
\Aelora\CSS::register($url, $name='', $version=false, $dependencies=[], $attributes=[]);
```

ParameterNotes$urlrequiredThe local or full url to the script to register$nameoptionalA name that can be used to later enqueue this script. It's also used as the `id` parameter when the script or style tag is output on the page. If it's omitted an MD5 hash is used instead.$versionoptionalA string representing the version of the script. If included it's appended to the URL as a query string in the `script` or `style` tag.$dependenciesoptionalAn array of other styles or scripts that this is dependent on. For example, if you have registered jQuery using the `name` `jquery`, you'd put that in this array.$attributesoptionalAny extra attributes added to the `script` or `style` tag.#### Enqueueing Files

[](#enqueueing-files)

You have two options for enqueueing a `script` or `style`.

If you just need to enqueue a URL, you can pass it into the `enqueue` method.

```
\Aelora\JS::enqueue('https://code.jquery.com/jquery-2.2.4.min.js');
```

With this line the full URL will be enqueued for output. Doing it this way you lose the ability to have this package handle dependencies.

The better option is to register the script or style and then enqueue it when you need to use it.

```
\Aelora\JS::register('jquery', 'https://code.jquery.com/jquery-2.2.4.min.js');
\Aelora\JS::enqueue('jquery');
```

When a script or style is enqueued any dependencies are also enqueued.

#### Writing to HTML

[](#writing-to-html)

In the head of your document you're going to call the `write()` method for both classes.

```

        My Page

```

This will dump out all the script and style tags linking to the files you've enqueued.

If you're using Blade templates you can use it like this.

```

        My Page
        {{ \Aelora\JS::write() }}
        {{ \Aelora\CSS::write() }}

```

#### Dequeueing

[](#dequeueing)

If there's something in the queue that you don't want for a specific view you can use the `dequeue` method.

```
\Aelora\JS::dequeue('jquery');
```

#### Clearing

[](#clearing)

If you need to clear out any registered scripts and styles and the queue.

```
\Aelora\JS::clear();
\Aelora\CSS::clear();

```

#### Reset

[](#reset)

This reloads the classes with new data from a config file, or falls back to the defaults if you don't give it a config file.

```
\Aelora\JS::reset('/path/to/config/file.php'); 	// Uses new file
\Aelora\JS::reset();							// Uses default config

```

Both classes have a `reset` method, but only the one in `JS` will actually reset and reload. `reset` in the `CSS` class only clears the registrations and queue from `CSS` and does not reload. The `reset` method in `JS` clears both classes and reloads.

### Configuration Files

[](#configuration-files)

Rather than registering and enqueueing a bunch of files in your startup scripts, you can also use a configuration file.

```
