2017 © Pedro Peláez
 

library asset-collector

Blade directives to prevent multiple asset (css/js) code insertions.

image

laraspells/asset-collector

Blade directives to prevent multiple asset (css/js) code insertions.

  • Friday, September 22, 2017
  • by emsifa
  • Repository
  • 1 Watchers
  • 0 Stars
  • 75 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 19 % Grown

The README.md

Asset Collector

Asset collector is a library with set of Blade directives to prevent multiple asset (css/js) code insertions. Asset collector used by LaraSpell for field components who need some css and js code., (*1)

For example, if you have view partial input-select2.blade.php like this:, (*2)

<select name="{{ $name }}" class="form-control use-select2" id="{{ $id }}">
  @foreach($options as $option)
  <option value="{{ $option['value'] }}">{{ $option['label'] }}</option>
  @endforeach
</select>

@push('styles')
<link rel="stylesheet" href="{{ asset('path/to/select2/select2.min.css') }}">
@endpush

@push('scripts')






@endpush

If you include (using @include) that file 2 times, link and scripts code will also rendered 2 times. So it will increase rendered page size and can be trouble for some plugins., (*3)

This library is just to prevent that case. Using asset collector, code above will be like this:, (*4)

<select name="{{ $name }}" class="form-control use-select2" id="{{ $id }}">
  @foreach($options as $option)
  <option value="{{ $option['value'] }}">{{ $option['label'] }}</option>
  @endforeach
</select>

@css('path/to/select2/select2.min.css')
@js('path/to/select2/select2.min.js')
@script





@endscript

Then in master view, you can dump collected assets like this:, (*5)

<!doctype html>
<html>
<head>
  ...
  @section('styles')
    @styles()
  @show
  ...
</head>
<body>
  ...
  @section('scripts')
    @scripts()
  @show
</body>
</html>

Installation

Run composer command below to install asset-collector:, (*6)

composer require "laraspells/asset-collector"

Then open your config/app.php, put LaraSpells\AssetCollectorServiceProvider::class to 'providers' section:, (*7)

Thats it!, (*8)

The Versions

22/09 2017

dev-master

9999999-dev

Blade directives to prevent multiple asset (css/js) code insertions.

  Sources   Download

MIT

by Muhammad Syifa