Loading in JavaScript that requires custom vars I'm rebuilding one of my works modules from Drupal 7 to Drupal 8 and I'm 99% of the way there the one thing I'm stuck on is in some cases I need to load in a external library that changes on a users location and other which is defined in a settings form:

In Drupal 7 I'd simply do it with:

drupal_add_js($proto.'://f1.'.$region.'readspeaker.com/script/'.$customerid.'/ReadSpeaker.js?'.$srcparams,array('group' =&gt; JS_DEFAULT, 'type' =&gt; 'file', 'scope'=&gt;'footer', 'preprocess' =&gt; FALSE));


But I'm not sure how to achieve this by creating a library in Drupal 8.
If the settings are global and don't vary per use, I'd implement hook_library_info_alter() and dynamically set the path there. JW Player does something like that: http://cgit.drupalcode.org/jw_player/tree/jw_player.module?h=8.x-1.x#n206

Remember to clear the cache when the settings are changed, so this is updated.

If it's something completely dynamic, or per user or so, you have to either write JS to load it or embed the js tag yourself, e..g with html_head.