Attaching libraries to specific controllers I want to include the google charts js library to a specific (or set of) controller(s).  In my library file, gcharts.libraries.yml, I have the following:

google_charts:
  remote: https://developers.google.com/chart
  version: current
  license:
    name: apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0
    gpl-compatible: true
  js:
    https://www.gstatic.com/charts/loader.js: { type: external, minified: true }
  dependencies:
    - core/jquery


Which, unless I copied something incorrectly, should be correct.

Question 1: is the dependencies tag allowed here?  The documentation isn't expressly clear on that.



My controller (GoogleChartsController) correctly instantiates and looks like:

&lt;?php
array(
  '#theme' =&gt; 'custom_theme',
  '#attached' =&gt;
    array(
      'library' =&gt;
        array('company/google_charts')
    ),
  // For testing purposes
  '#cache' =&gt; array(
    'max_age' =&gt; 0,
  )
);
?&gt;


However, when I look through the source I don't see the library that I told my controller has a dependency for.  My library never loads.

Question 2: Do I have have to use the hook_page_attachement or the hook_preprocess_page hooks?  If so, how do I limit it to use just my set of controllers I want (I don't need or want this loading on every page)?  Can I get the path, check to see that it is what I want and then add it conditionally, like so?  Or is there some other way?



My custom-theme.html.twig looks like:

&lt;div id="testing-div"&gt;Are we here?&lt;/div&gt;
&lt;!-- inflate chart here --&gt;
&lt;div id="chart-div"&gt;&lt;/div&gt;


The documentation isn't crystal clear as to when and where to include inline js.  From the google charts api, I'm to include something like:

&lt;script type="text/javascript"&gt;
  // Load the Visualization API and the piechart package.
  google.charts.load('current', {'packages':['corechart']});
  // Set a callback to run when the Google Visualization API is loaded.
  google.charts.setOnLoadCallback(drawChart);
  // issue google charts api call to inflate chart at "chart-div"
  // omitted rest for brevity
&lt;/script&gt;


Now, my intuition is that I can actually abstract each of the charts I want into their own "library" and add the dependency, because of the way I designed things, this will be fairly trivial.  But I'm not certain if this is the best way to do it.  But I've read that you can dump inline js into twig files; but I'm not 100% certain this applies here...

Question 3: Is adding the js into twig best practices or is libraries the way to go?  Assuming libraries, can I include several libraries into one library file and just include the one(s) that I want/need?  So I would have one library for customized_charts.libraries.yml and in there there would be declarations for pie_chart, bar_chart, etc.  And then I would load module/bar_chart when I wanted to display bar charts, etc?
You are not indenting parts of the yml file that you need to indent.

Look at this example from token.libraries.yml at /modules/contrib/token/token.libraries.yml:

jquery.treeTable:
  remote: 'http://plugins.jquery.com/treetable/'
  version: 3.2.0
  license:
    name: MIT
    url: https://github.com/ludo/jquery-treetable/blob/3.2.0/MIT-LICENSE.txt
    gpl-compatible: true
  js:
    js/jquery.treetable.js: {}
  css:
    component:
      css/jquery.treetable.css: {}
      css/token.treetable.theme.css: {}
  dependencies:
    - core/jquery


Also, pay attention to colons, since they are part of YAML syntax.

use:

remote: 'remote: https://developers.google.com/chart'


not 

remote: remote: https://developers.google.com/chart