3

I've installed eu-cookie-compliance module in few projects and everywhere it worked as expected but in one project I have problems with loading JavaScript in correct order. Even if I implement hook_js_alter and set higher weights, eu-compliance JavaScript is loaded before misc/drupal.js and misc/jquery.js. Is there any better way to reorder this JavaScript?

1 Answer 1

9

You could always change the group it's in:

function MYMODULE_js_alter(&$js) {
  $js['path/to/eu-cookie-compliance.js']['group'] = JS_DEFAULT;
}

Drupal's misc JS, jQuery etc, should all be in JS_SYSTEM, which has a lower weighting than JS_DEFAULT. There's also JS_THEME which has a height weighting than JS_DEFAULT.

The drupal_add_js() docs discuss the whole JS weighting thing in much greater detail.

6
  • I tried everything what you wrote. I even set group and weight in drupal_add_js - no result. Apr 15, 2013 at 13:08
  • 1
    Any chance you've got another module on that site interfering with the JS? I use that method in pretty much every site (and all of those have the eu cookie module installed) to reduce the number of aggregated JS files and it's never failed to work. You might try setting $js['path/to/eu-cookie-compliance.js']['every_page'] = TRUE; as a test as well
    – Clive
    Apr 15, 2013 at 13:13
  • No, still not working. Apr 15, 2013 at 13:25
  • Have you confirmed the same behaviour on a blank install of Drupal? It would rule out your specific site instance being the problem at least
    – Clive
    Apr 15, 2013 at 14:00
  • That's the oddest think, I have used this module on Drupal 6 and Drupal 7 installation, but only here eu-cookie-compliance.js is outputted at the beginning of $scripts variable. Apr 15, 2013 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.