Javascript libraries attached in HEAD not loaded

Created on 7 July 2025, 3 months 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
    3 months ago
    Total: 49s
    #541325
  • Merge request !168Process html_head for JS libraries β†’ (Merged) created by atowl
  • Pipeline finished with Success
    3 months 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!

  • πŸ‡ΊπŸ‡ΈUnited States imran1217

    I have validate the patch in #7 and its working fine.

  • Pipeline finished with Skipped
    2 months ago
    #549524
    • atowl β†’ committed f70cbf02 on 8.x-1.x
      Issue #3534375 by atowl, guillaumeg, imran1217: Javascript libraries...
  • πŸ‡³πŸ‡ΏNew Zealand atowl

    Thanks for all the work, merging this, and it'll be in the next release shortly.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024