The current disabled scripts functionality only uses hook_js_alter, but this doesn't cover all scripts in the page. For example google_tag adds the script tag into hook_page_attachments - $attachments['#attached']['html_head']

Comments

dragos-dumi created an issue. See original summary.

dragos-dumi’s picture

Status: Active » Needs review
StatusFileSize
new2.02 KB
svenryen’s picture

Thanks for the patch. I have a question. From what I understand we change module weight so that hooks run after other modules have added their scripts. What happens if another module has weight 1, weight 0 or weight -1 (or lower) and that module defines a javascript?

dragos-dumi’s picture

That's a valid point. Since most of the modules comes with weight 0, this should work for most cases.
Maybe as an improvement we could add in the config screen a notice about this, that the developer might need to adjust the weight.
What do you think?

svenryen’s picture

It would be great if it can also happen automatically.

How about if we loop through the weights of all other modules and sets the weight of this module higher than the current highest?

And in addition to that, instead of the proposed field, can we have a button that when clicked makes sure the weight of this module is the highest again (presuming they've installed some other module that for example has the weight of 1000 after they installed EU cookie compliance?) If the process is not automated for the user, they would have to inspect all relevant modules to see what's the currently highest value, which would be a pain.

svenryen’s picture

Status: Needs review » Needs work
svenryen’s picture

Assigned: dragos-dumi » svenryen
svenryen’s picture

StatusFileSize
new3.51 KB

Here is an updated patch that also checks the weight of other modules and makes this module load at the end, adding an exclusion list for modules that are allowed to have higher weight (for #2933614: [2.x?] How to block cookies until the user accepts, for example Google Analytics cookies? we need to let google_analytics load after this module). For now, Google Analytics is added to the exclusion list, and we should be able to add other modules to the exclusion list later, when needed.

The weight is reset every time the config form is saved, addressing the issue where a module with higher weight is added after this module is installed.

svenryen’s picture

Status: Needs work » Fixed

  • svenryen committed f4141ec on 8.x-1.x authored by dragos-dumi
    Issue #2962641 by svenryen, dragos-dumi: Check for disabled scripts in...

Status: Fixed » Closed (fixed)

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