Closed robov closed 7 years ago
How can I load the required js assets from a CDN ? To speed up my site loading select2.js and select2-krajee.js from a CDN would increase in must faster response times
Thanks... but where do I specify that ?
Like my bootstrap in main.php
'bundles' => [
// // use bootstrap css from CDN
'yii\bootstrap\BootstrapAsset' => [
'sourcePath' => null, // do not use file from our server
'css' => [
or do I need to create a new asset file and load that somehow ?
This is a piece of cake to do in Yii 2. Just override your asset bundle in your yii2 application config as mentioned in this customizing asset bundle guide for Yii 2.
Thanks... apparently I am still doing something not quite right, as I get a select2 is not a function
The original working code loads the local assets
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="/assets/46aff460/js/select2.full.js"></script>
<script src="/assets/46aff460/js/select2-krajee.js"></script>
When I try to override with
'kartik\select2\Select2Asset' => [
'sourcePath' => null, // do not publish the bundle
'js' => [
'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.full.min.js',
'https://cdn.jsdelivr.net/gh/kartik-v/yii2-widget-select2@2.1.0/assets/js/select2-krajee.min.js',
]
],
The the code loads
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.full.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/kartik-v/yii2-widget-select2@2.1.0/assets/js/select2-krajee.min.js"></script>
But then I get a error "VM1202:2 Uncaught TypeError: jQuery(...).select2 is not a function" when I try to use select2 in my modal (with the original code it works like a charm... just slow loading....
Any suggestions ?
Prerequisites
master
branch of yii2-widget-select2.Steps to reproduce the issue
1. 2. 3.
Expected behavior and actual behavior
When I follow those steps, I see...
I was expecting...
Environment
Browsers
Operating System
Libraries
Isolating the problem