1

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?

B Faley
  • 17,120
  • 43
  • 133
  • 223

1 Answers1

0

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.

dragontree
  • 1,709
  • 11
  • 14
  • This is only true for multiple instances of the same report widget. If you have two instances of two separate widgets, they wont be able to know that a javascript file has already been included. Try it! – B Faley Feb 08 '17 at 21:01
  • I'm using 5 different report widgets and 3 js files are loaded in each widget. Although I'm calling the `addJs()` in the widgets `render()` function. This way the assets are not loaded multiple times. – dragontree Feb 09 '17 at 07:24