PHPackages                             zanozik/cdnjs - 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. zanozik/cdnjs

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

zanozik/cdnjs
=============

Install, update, manage and test CDNjs assets

v1.0(8y ago)029MITPHPPHP &gt;=5.6.4

Since Jun 18Pushed 7y ago1 watchersCompare

[ Source](https://github.com/zanozik/cdnjs)[ Packagist](https://packagist.org/packages/zanozik/cdnjs)[ RSS](/packages/zanozik-cdnjs/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (2)Dependencies (2)Versions (4)Used By (0)

CDNjs Asset Manager
===================

[](#cdnjs-asset-manager)

[![Latest Version on Packagist](https://camo.githubusercontent.com/af0b8083352f5fe5fc8d67fbddb193c41cb44032d603b5300b4090b7e22d5867/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f7a616e6f7a696b2f63646e6a732e737667)](https://packagist.org/packages/zanozik/cdnjs)[![Packagist Downloads](https://camo.githubusercontent.com/627ec0938e27fb901ec2ae012b33fecb5a1f6b97ee79564efd565b0ccb7859aa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7a616e6f7a696b2f63646e6a732e737667)](https://packagist.org/packages/zanozik/cdnjs)[![Github Downloads](https://camo.githubusercontent.com/917e55e193c0ca14bf7cabd987edfe94a7ebb2f97d2855d2772a3d9726124fc9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f646f776e6c6f6164732f7a616e6f7a696b2f63646e6a732f746f74616c2e737667)](https://github.com/zanozik/cdnjs)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE)

CDNjs Asset Manager helps you install, update, manage and test CDNjs assets in your Laravel app. It uses custom helper `cdnjs()` and Blade directive (deprecated!) to include appropriate assets in your template by an alias you define. All assets are stored in database and cached on the first request indefinitely.

Front-end of the manager lets you add, edit, update and test assets, fetching them directly from CDNjs. You can also set up a scheduler to automatically check for (and even update to) new version of the asset, according to version mask you define.

Examples
--------

[](#examples)

You can add something like this in your blade template or partial:

```

        {!! cdnjs(['bootstrap-css','select2-css']) !!}

        @cdnjs(bootstrap-css|select2-css)

......

    {!! cdnjs(['jquery','bootstrap-js','select2-js']) !!}

    @cdnjs(jquery|bootstrap-js|select2-js)

```

And you will get an output like this:

```

```

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

[](#installation)

Require the package by running in your console:

```
composer require zanozik/cdnjs:dev-master

```

Add `Zanozik\Cdnjs\CdnjsServiceProvider::class` to the end of the `providers` array:

```
// config/app.php
'providers' => [
    ...
    Zanozik\Cdnjs\CdnjsServiceProvider::class,
],

```

Publishing assets and running migration is easy:

```
php artisan package:install

```

This will do all of the following:

- Create `assets` table in your database,
- Seed it with sample data (used to render cdnjs Asset manager, as example)
- Create `config/cdnjs.php` configuration file
- Create `resources/lang/en/cdnjs.php` English language file
- Create `resources/view/vendor/cdnjs/index.php` and `resources/view/vendor/cdnjs/edit.php`CDNjs Asset Manager blade template files for your convenience.

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

[](#configuration)

`config/cdnjs.php` file consists of routes, url and time options. You can change them according to your needs, although default setting should also work just fine.

Change to desired time for daily version check and autoupdate (assign `false` if you want to completely disable this feature):

```
	/*
	|--------------------------------------------------------------------------
	| Daily version update check time (H:i)
	|--------------------------------------------------------------------------
	|
	*/
	'time' => '0:00'

```

Route prefix and middleware you want to use:

```
	/*
	|--------------------------------------------------------------------------
	| Routes group config
	|--------------------------------------------------------------------------
	|
	*/
	'route' => [
		'prefix' => 'cdnjs',
		'middleware' => 'web'
	],

```

Change prefix to whatever you want to appear before the path to you cdnjs Asset Manager. By default the path is `/cdnjs/assets`, so you can change it to something like, `/admin/assets`by assigning `'prefix' => 'admin',`. You can even disable prefix by assigning an empty string and call the route by `/assets`.

You can add more middlewares by an array, if you need to, like this:

```
	/*
	|--------------------------------------------------------------------------
	| Routes group config
	|--------------------------------------------------------------------------
	|
	*/
	'route' => [
		'prefix' => 'cdnjs',
		'middleware' => [
		    'web',
		    'auth'
        ],
	],

```

Usage
-----

[](#usage)

### Manager

[](#manager)

Click on *Add new asset* and search for desired library by entering partial keyword in *Type* select search box on opened modal.

[![Screenshot](https://camo.githubusercontent.com/16ef81d1b4779bd7242ca56f03ce83b917e7cc2316002ed52d97613aad1b6c10/687474703a2f2f692e696d6775722e636f6d2f4256553242364c2e706e67)](https://camo.githubusercontent.com/16ef81d1b4779bd7242ca56f03ce83b917e7cc2316002ed52d97613aad1b6c10/687474703a2f2f692e696d6775722e636f6d2f4256553242364c2e706e67)

Choose desired version and asset, your custom alias (name) to call from your templates, default will be generated for you. If you want to use version check, choose *Version check* and *Autoupdate* masks. Make sure you configured you cron scheduler correctly, if you want to use version checks (refer to[Task Scheduling](https://laravel.com/docs/5.4/scheduling) on Laravel website)

[![Screenshot](https://camo.githubusercontent.com/26067652e72b77d35bed3c1a72ba93ded81cd0f080e9bf3f3da7314d2aaacfb1/687474703a2f2f692e696d6775722e636f6d2f453051385562522e706e67)](https://camo.githubusercontent.com/26067652e72b77d35bed3c1a72ba93ded81cd0f080e9bf3f3da7314d2aaacfb1/687474703a2f2f692e696d6775722e636f6d2f453051385562522e706e67)

*Autoupdate mask* cannot be wider than *Version check mask*.

If a new version is found automatically, according to defined masks, during the version check, cdnjs Asset Manager will record the version and let you test and update to it.

It will automatically update current version to a new version, if a new version happens to fall under defined *Autoupdate mask*.

The package will also fire predefined `Events`.

Handling events
---------------

[](#handling-events)

The package can fire two events:

- `\Zanozik\Cdnjs\Events\NewAssetVersion`
- `\Zanozik\Cdnjs\Events\AssetVersionUpdated`

The package will pass `Asset` collection with each `Event`.

You can listen for and catch these events any way you want (read further about[Events](https://laravel.com/docs/5.4/events) on Laravel website).

#### Example:

[](#example)

Create app/Listeners/NewVersionListener.php

```
