Blade directive to get asset URLs according to environment.
bryanjhv/laravel-blade-cdn is a Laravel package for blade directive to get asset urls according to environment..
It currently has 2 GitHub stars and 178 downloads on Packagist (latest version 1.0.2).
Install it with composer require bryanjhv/laravel-blade-cdn.
Discover more Laravel packages by bryanjhv
or browse all Laravel packages to compare alternatives.
Last updated
A Blade directive for getting asset URLs according to app environment.
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
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="https://raw.githubusercontent.com/bryanjhv/laravel-blade-cdn/refs/heads/main//code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://raw.githubusercontent.com/bryanjhv/laravel-blade-cdn/refs/heads/main//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.
This project is released under the MIT license.