2017 © Pedro Peláez
 

library enqueuer

Laravel package to enqueue css and js files for load. It supports dependencies, caching and passing data to scripts from PHP.

image

morningtrain/enqueuer

Laravel package to enqueue css and js files for load. It supports dependencies, caching and passing data to scripts from PHP.

  • Thursday, June 30, 2016
  • by morningtrain
  • Repository
  • 4 Watchers
  • 5 Stars
  • 158 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 1 % Grown

The README.md

enqueuer

Software License , (*1)

Laravel package to enqueue css and js files for load. It supports dependencies, to serve files in the correct order, caching, magic methods and passing along PHP variables., (*2)

Install

Via Composer, (*3)

``` bash $ composer require morningtrain/enqueuer, (*4)

Add this service provider to your config/app.php file.

``` php
morningtrain\enqueuer\enqueuerServiceProvider::class,

Usage

In all of the below cases, "Admin" can be any word and is used to group styles and scripts. A common use case is to have different scripts in admin and frontend., (*5)

To enqueue a script or style

``` php, (*6)

Enqueuer::addAdminScript('jquery', [ 'location' => 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js' ]);, (*7)

Enqueuer::addAdminScript('sample', [ 'content' => "console.log('sample');", 'dependencies' => ['jquery'] ]);, (*8)


The syntax for adding styles and scripts are almost the same. The main difference is that you would call "addAdminStyle" in the above example instead. In addition, note that it is not possible to use the data property with styles. ### Script dependencies Some scripts and styles might be dependent on others. To solve this, one can add the dependencies property. The value of this property is an array that contains the names of all the script/styles it is dependent on. The scripts/styles will be sorted according to the dependencies. ``` php Enqueuer::addAdminScript('sample', [ 'content' => "console.log('sample');", 'dependencies' => ['jquery'] ]); Enqueuer::addAdminScript('jquery', [ 'location' => 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js' ]);

Pass PHP data to script

It is possible to pass on a data object to a script by including the data properties., (*9)

The value of data is an array containing the name of the object and the properties., (*10)

``` php Enqueuer::addProfileScript('config_test', [ 'content' => "console.log(config.baseUrl);", 'data' => [ 'object' => 'config', 'properties' => [ 'baseUrl' => url('') ] ] ]);, (*11)


### Including script and styles in views To include scripts in view ``` php {!! Enqueuer::getAdminScripts() !!}

To include styles in view, (*12)

``` php, (*13)

{!! Enqueuer::getAdminStyles() !!}, (*14)


### Cache control #### Clear all caches Clear everything ``` php Enqueuer::clearAllCache();

To clear all caches for scripts ``` php, (*15)

Enqueuer::clearScriptsCache();, (*16)


To clear all caches for styles ``` php Enqueuer::clearStylesCache();

To clear all caches for scripts in group (admin in this case) ``` php, (*17)

Enqueuer::clearAdminScriptsCache();, (*18)


To clear all caches for styles in group (admin in this case) ``` php Enqueuer::clearAdminStylesCache();

Managing settings

Settings can be overwritten at any time using this snippet: ``` php, (*19)

Enqueuer::configure([ 'cacheScripts' => true, 'cacheStyles' => true, 'alwaysGenerateStylesCache' => false, 'alwaysGenerateScriptsCache' => false, 'storageDisk' => 'public' ]);, (*20)

```, (*21)

It allows for enabling / disabling cache for scripts and styles, as well as allowing the cache for being regenerated on every request. Note, that in order to use it without caching, all enqueued scripts have to be publicly available on the provided url., (*22)

Change log

Please see CHANGELOG for more information what has changed recently., (*23)

Security

If you discover any security related issues, please email mail@morningtrain.dk instead of using the issue tracker., (*24)

Credits

License

GNU General Public License v3.0. Please see License File for more information., (*25)

The Versions

30/06 2016

dev-master

9999999-dev https://github.com/morningtrain/laravel-enqueuer

Laravel package to enqueue css and js files for load. It supports dependencies, caching and passing data to scripts from PHP.

  Sources   Download

GNU GPL v3.0

The Requires

 

The Development Requires

laravel css js morningtrain enqueuer

30/06 2016

1.2.6

1.2.6.0 https://github.com/morningtrain/laravel-enqueuer

Laravel package to enqueue css and js files for load. It supports dependencies, caching and passing data to scripts from PHP.

  Sources   Download

GNU GPL v3.0

The Requires

 

The Development Requires

laravel css js morningtrain enqueuer

14/01 2016

1.2.5

1.2.5.0 https://github.com/morningtrain/laravel-enqueuer

Laravel package to enqueue css and js files for load. It supports dependencies, caching and passing data to scripts from PHP.

  Sources   Download

GNU GPL v3.0

The Requires

 

The Development Requires

laravel css js morningtrain enqueuer

14/01 2016

1.2.4

1.2.4.0 https://github.com/morningtrain/laravel-enqueuer

Laravel package to enqueue css and js files for load. It supports dependencies, caching and passing data to scripts from PHP.

  Sources   Download

GNU GPL v3.0

The Requires

 

The Development Requires

laravel css js morningtrain enqueuer

07/01 2016

1.2.3

1.2.3.0 https://github.com/morningtrain/laravel-enqueuer

Laravel package to enqueue css and js files for load. It supports dependencies, caching and passing data to scripts from PHP.

  Sources   Download

GNU GPL v3.0

The Requires

 

The Development Requires

laravel css js morningtrain enqueuer

19/12 2015

1.2.2

1.2.2.0 https://github.com/morningtrain/laravel-enqueuer

Laravel package to enqueue css and js files for load. It supports dependencies, caching and passing data to scripts from PHP.

  Sources   Download

GNU GPL v3.0

The Requires

 

The Development Requires

laravel css js morningtrain enqueuer

19/12 2015

1.2.1

1.2.1.0 https://github.com/morningtrain/laravel-enqueuer

Laravel package to enqueue css and js files for load. It supports dependencies, caching and passing data to scripts from PHP.

  Sources   Download

GNU GPL v3.0

The Requires

 

The Development Requires

laravel css js morningtrain enqueuer

13/12 2015

v1.2.0

1.2.0.0 https://github.com/morningtrain/laravel-enqueuer

Laravel package to enqueue css and js files for load. It supports dependencies, caching and passing data to scripts from PHP.

  Sources   Download

GNU GPL v3.0

The Requires

 

The Development Requires

laravel css js morningtrain enqueuer

13/12 2015

v1.1.1

1.1.1.0 https://github.com/morningtrain/laravel-enqueuer

Laravel package to enqueue css and js files for load. It supports dependencies, to serve files in the correct order. Caching included.

  Sources   Download

GNU GPL v3.0

The Requires

 

The Development Requires

morningtrain enqueuer

13/12 2015

v1.1.0

1.1.0.0 https://github.com/morningtrain/laravel-enqueuer

Laravel package to enqueue css and js files for load. It supports dependencies, to serve files in the correct order. Caching included.

  Sources   Download

MIT

The Requires

 

The Development Requires

morningtrain enqueuer

12/12 2015

v1.0.0

1.0.0.0 https://github.com/morningtrain/laravel-enqueuer

Laravel package to enqueue css and js files for load. It supports dependencies, to serve files in the correct order. Caching included.

  Sources   Download

MIT

The Requires

 

The Development Requires

morningtrain enqueuer