A Yii Framework 2 component for using assets in different environments (Local/CDNs)
A Yii Framework 2 component for using assets in different environments (Local/CDNs)
Production Ready: Used in several real projects is enough to prove its stability.
Minimum requirements: PHP 7.0+ / Yii2 Framework 2.0.12+
Bugs / Feature Request?: Create your issue here.
The preferred way to install this extension is through composer.
Either run
composer require --prefer-dist blacksmoke26/yii2cdn "*"
or add
"blacksmoke26/yii2cdn": "*"
to the require section of your composer.json
file.
Info: This tutorial will demonstrate how to use FancyBox3
library in a production
(online/CDN) or development
(local/offline) environment.
cdn
directory under the /root/web
folder.FancyBox3
library under cdn
directory./root/web/cdn/jquery-fancybox
.@app/config/main.php
in your code editor.cdn
under components
section like the following code:// ...
'components' => [
// ...
'cdn' => [
'class' => '\yii2cdn\Cdn',
'baseUrl' => '/cdn',
'basePath' => dirname(__DIR__) . '/web/cdn',
'components' => [
'jquery-fancybox' => [
'css' => [
'@attributes' => [
'noNameInPathUrls' => true, // Hide /css in urls
],
[
'dist/jquery.fancybox.css', // offline version
'@cdn' => '//cdnjs.cloudflare.com/ajax/libs/fancybox/3.3.5/jquery.fancybox.min.css', // online version
],
],
'js' => [
'@attributes' => [
'noNameInPathUrls' => true, // Hide /js in urls
],
[
'dist/jquery.fancybox.js', // offline version
'@cdn' => '//cdnjs.cloudflare.com/ajax/libs/fancybox/3.3.5/jquery.fancybox.min.js', // online version
],
],
],
],
],
// ...
],
// ...
//...
Yii::$app->cdn->get('jquery-fancybox')->register();
//...
Now it’s time to play around, See ya!