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' => JS_DEFAULT, 'type' => 'file', 'scope'=>'footer', 'preprocess' => FALSE));

But I'm not sure how to achieve this by creating a library in Drupal 8.

1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.