Although this is a good thing, sometimes you do need jQuery (for example to use Ajax, in which case you'd also need other scripts). So how do you load these files? One way is to use hook_page_attachments() to
#attach your own library to the page. However, this is only recommended if the assets you need to attach do not apply to something specific, but to the entire page. The recommended way is to attach the library to a render array because then it will only get loaded if necessary.
And if we look at the documentation page for assets, we'll see how we can add our own library. We need to create a
my_theme.libraries.yml file. And inside, we can add the following:
my_scripts will be the name of the library we will reference when attaching.
$render_array['#attached']['library'] = 'my_module/my_scripts';
Hope this helps.
Danny founded WEBOMELETTE in 2012 as a passion project, mostly writing about Drupal problems he faced day to day, as well as about new technologies and things that he thought other developers would find useful. Now he now manages a team of developers and designers, delivering quality products that make businesses successful.