Javascript libraries attached in HEAD not loaded

Created on 7 July 2025, 5 days ago

Problem/Motivation

It appears that js libraries attached in hook_page_attachments(), in the ['#attached']['html_head'] get added to the unverified script list and therefor are not loaded onto the page.

Steps to reproduce

Proposed resolution

Remaining tasks

* reproduce
* fix

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇳🇿New Zealand atowl

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @atowl
  • 🇳🇿New Zealand atowl

    Uploading the patch that was supplied in the previous issue 🐛 disabled scripts not being included after consent Active from @guillaumeg. It is the same file, just renamed to suit this issue so it can be discussed here.

  • 🇳🇿New Zealand atowl
  • 🇳🇿New Zealand atowl

    For a reproduction so far i have tried
    - install drupal/google_tag^1.8
    - set up a new container (my_first_container), all fake-ish data and defaults.
    - changed to opt-in with categories
    - created 2 categories, one for my testing, and one for analytics (both unchecked by default).
    - added my disabled javascripts

    test_module:modules/custom/test_module/js/console_log.js|test_module
    analytics:https://www.googletagmanager.com/gtag.js
    analytics:sites/default/files/google_tag/my_first_container/google_tag.script.js
    

    Now accepting the analytics category i don't see either of the two scripts pop up, however ever, applying @guillaumeg's patch, i see the both appear.

    I think this is the reproduction that i'm looking for.

  • 🇦🇺Australia GuillaumeG

    Hi @atowl,

    It sounds very much like the issue I had, and the patch seems to have fixed it now. :)

  • Pipeline finished with Success
    5 days ago
    Total: 49s
    #541325
  • Merge request !168Process html_head for JS libraries → (Open) created by atowl
  • Pipeline finished with Success
    5 days ago
    Total: 48s
    #541330
  • 🇳🇿New Zealand atowl

    Hi @guillaumeg,

    I've attached a patch of the MR, if you could just confirm that works i'll look to merge it for the next release.

    Thanks!

Production build 0.71.5 2024