OctoberCMS: How to check if a js file has been already included by another widget

200 views Asked by At

I have got two Report Widget classes both of which use highcharts.js library. So both of them should include highcharts.js before being rendered. Therefore they implement the loadAssets method:

public function loadAssets()
{
    $this->addJs('js/highcharts.js');
}

The problem is that I should not call addJs method if another report widget has already been added to the page, otherwise highcharts.js will be included in the backend dashboard twice. How can I check to avoid adding the js file multiple times?

1

There are 1 answers

2
dragontree On

When using the addJs() and addCss() functions, October itself checks if the asset is already loaded and if it is, it is not loaded again.