I have a use case where i want to dynamic add library , Attributes of library will vary with page. In my case the $callback will be different depending on the page.
$libraries['sample.my-lib'] = [
'js' => [
'//maps.googleapis.com/maps/api/js?'.$key.'&callback='.$callback
=> [
'type' => 'external',
'attributes' => [
'async' => "true",
'defer'=> 'true'
],
],
],
'weight' => '2200',
];
The above code works but when i navigate to different page i have to clear the cache to get updated value of $callback.
I have tried hook_library_info_alter but library definition is still cached.
How can i work around it to make my use case work.