When logged in as a user (not admin), some JS scripts do not load on certain pages.
I found out about this issue because I am using the module EU Cookie Compliance and the scripts it uses (
js.cookie.min.js) aren't always loaded.
I am using a JS method provided by the EU Cookie Compliance module in my custom theme and found out it triggered an error on some pages (because the scripts aren't loaded).
For example, the scripts load on
/user/2 but don't on
/user/2/customer as you can see on the below image. Why does this happen?
I can see no option in EU Cookie Compliance module that prevents loading the script on some pages. Nor did I find anything in the code.
- Drupal core: 8.9.3
- EU Cookie Compliance: 8.x-1.9
I have now included
eu_cookie_compliance as a dependency in my theme:
dependencies: - core/drupal - core/jquery - core/jquery.once - core/drupalSettings - eu_cookie_compliance/eu_cookie_compliance - eu_cookie_compliance/eu_cookie_compliance_bare
And this fixed the fact that the scripts weren't loaded on all pages. That said, I now have errors on these specific pages.
All I do in my theme's JS (
radix_sub.script.js) is using
Drupal.eu_cookie_compliance.hasAgreed() which now triggers the following errors:
I have tried declaring only
eu_cookie_compliance and only
eu_cookie_compliance_bare and both in my theme libraries, and the errors are identical.