Score:0

Why does adding data- attributes to JavaScript libraries prevent them from being aggregated?

pa flag
Ian

I'm having an issue with adding a data attribute to my preprocessed / aggregated javascript within my theme.

When I have preprocessing disabled, I am able to add a data attribute to individual files within the .libraries.yml file as suggested within the Drupal docs. {attributes: {data-example-attribute: true}}

However once I enable ['js']['preprocess'] = true; to the settings.php file instead of my theme JS being aggregated into a single file they do not get aggregated at all.

Is there a hook that I'm missing which I could use to just prepend a data attribute onto the preprocessed JS file.

Using Drupal 9

id flag
What should happen to the attributes on a script tag that aggregates multiple files if two libraries specify different values for the same data- attribute?
Ian avatar
pa flag
Ian
@cilefen Thanks for your reply. In this instance all the files within the library require the same data attribute.
id flag
This issue seems like it is related, although if I am reading it right it could cause issues with `data-` attributes if merged, because it does not account for attribute values: https://www.drupal.org/project/drupal/issues/1587536
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.