I have one view in which I need to call JQuery in my header along with another JS Library. For all other pages they can be rendered at the end of the document. What's the best way to achieve this in Yii2?
Currently I am just doing this in my AppAsset.php
public $js = [
'https://code.highcharts.com/highcharts.js',
];
public $jsOptions = ['position' => \yii\web\View::POS_HEAD];
I have looked at making a new Asset, but it didn't seem to work and I wasn't sure if it was the right way to go about it. As I don't want to render the JS first in every page.
<?php
namespace app\assets;
use yii\web\AssetBundle;
class EarlyJavaScriptAsset extends AssetBundle
{
public $js = [
'https://code.highcharts.com/highcharts.js',
];
public $jsOptions = ['position' => \yii\web\View::POS_HEAD];
public $publishOptions = [
'only' => [
'report/report-1', // this is view folder location
]
];
}