bryanjhv / laravel-blade-cdn by bryanjhv

Blade directive to get asset URLs according to environment.
178
2
3
Package Data
Maintainer Username: bryanjhv
Maintainer Contact: bryanjhv@gmail.com (Bryan Horna)
Package Create Date: 2016-08-14
Package Last Update: 2016-11-20
Language: PHP
License: MIT
Last Refreshed: 2024-11-22 03:13:28
Package Statistics
Total Downloads: 178
Monthly Downloads: 2
Daily Downloads: 0
Total Stars: 2
Total Watchers: 3
Total Forks: 1
Total Open Issues: 0

Laravel Blade CDN

A Blade directive for getting asset URLs according to app environment.

Installation

Require this package with Composer using the following command

composer require bryanjhv/laravel-blade-cdn

After updating Composer, add the service provider to the providers array in your config/app.php file:

Bryanjhv\BladeCdn\BladeCdnServiceProvider::class,

Finally, publish the config file, so you can configure your own CDN aliases and prefix:

php artisan vendor:publish --provider="Bryanjhv\BladeCdn\BladeCdnServiceProvider" --tag=config

Usage

Important: First at all, please remove all your cached views, using:

php artisan view:clear

The service provider makes the @cdn Blade directive available, so you can use it like so (working on resources/views/sample.blade.php):

<link rel="stylesheet" href="@cdn('bootstrap-css')" />
<script src="@cdn('jquery')"></script>
<script src="@cdn('bootstrap-js')"></script>
<script src="@cdn('js/main.js')"></script>

The above code will be expanded, in production, using the default configuration file the package ships with, to:

<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="<?php echo asset('js/main.js'); ?>"></script>

Or, in any other environment, to:

<link rel="stylesheet" href="<?php echo asset('css/bootstrap.min.css'); ?>" />
<script src="<?php echo asset('js/jquery.min.js'); ?>"></script>
<script src="<?php echo asset('js/bootstrap.min.js'); ?>"></script>
<script src="<?php echo asset('js/main.js'); ?>"></script>

Of course, you may define any custom alias and prefix after publishing the configuration by editing the config/blade-cdn.php file.

License

This project is released under the MIT license.