Without advagg enabled jQuery is loaded before drupal.js

With advagg enabled drupal.js loads before jQuery resulting in jQuery not defined error.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mikeytown2’s picture

I would like to be able to repo this as I currently do not have this issue and thus do not know where to look if I want to attempt to fix this :)

What JS related modules do you have enabled (jquery update, LABjs, magic, etc)?
How is AdvAgg configured (enabled sub modules and settings)?
What theme are you using?
Any other info that might be related?

andrewhine’s picture

Hi

Sorry I forgot to mention we're using Google CDN for jQuery.

I tried the patch https://drupal.org/node/2039297 but to no avail.

JS related modules we have: jQuery Update 7.x-2.3+15-dev no others you mention or other JS related modules I can see.

We are also using the CDN module (but it is disabled in our dev environment where the issue occurs - we've not/can't try in prod with the CDN module).

The initial script order is:

soccialize.js?
cdn.gigya.com/JS

modernizr.custom.22686.js?n19y67
/sites/all/libraries/modernizr

jquery.js
ajax.googleapis.com/ajax/libs/jquery/1.8.2

jquery-ui.js
ajax.googleapis.com/ajax/libs/jqueryui/1.10.2

jquery.once.js?v=1.2
/misc

drupal.js?n19y67
/misc

...

After a

drush en advagg -y

The script order is:

socialize.js?
cdn.gigya.com/JS

drupal.js?n1a8ic
/misc

jquery.once.js?v=1.2
/misc

jquery.fancybox-1.3.4.js?n1a8ic
/sites/all/themes/intrepid_theme/fancybox

jquery.mousewheel-3.0.4.pack.js?n1a8ic
/sites/all/themes/intrepid_theme/fancybox

jquery.easing.1.3.js?n1a8ic
/sites/all/themes/intrepid_theme/js

jquery.js
ajax.googleapis.com/ajax/lib

And the console has the error

drupal.js:5

"Uncaught ReferenceError: jQuery is not defined"

And not much of our site works!

Many thanks

mikeytown2’s picture

I tried to repo this on a fresh D7 install.

Initial Modules Installed:
https://drupal.org/project/gigya
https://drupal.org/project/modernizr
https://drupal.org/project/jquery_update
https://drupal.org/project/token
https://drupal.org/project/entity
https://drupal.org/project/ctools
https://drupal.org/project/libraries

Enable AdvAgg via
drush en advagg -y

Result:
I can't repo this bug. https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js gets loaded right after gigya but before drupal.js

What information is under the "AdvAgg CSS/JS hooks implemented by modules" section on the admin/config/development/performance/advagg/info page? Also what happens when you disable gigya? Reason I ask about gigya is this issue #2020717: Why is gigya adding it's JS in the head above JS and CSS.

andrewhine’s picture

Hi Mikey,

Thanks for your reply.

It turns out the gigya module is disabled due to issues we had with it and we've created our own gigya module based on the original gigya module. Disabling our module so the gigya script is not loaded at all does not fix the problem.

Under the "AdvAgg CSS/JS hooks implemented by modules" is:

advagg: 5
advagg_build_aggregate_plans_alter
advagg_context_alter
advagg_save_aggregate_alter
css_alter
js_alter

clientside_validation: 1
js_alter

domain_conf: 1
js_alter

locale: 2
css_alter
js_alter

not in use: 11
advagg_changed_files
advagg_css_groups_alter
advagg_current_hooks_hash_array_alter
advagg_get_css_aggregate_contents_alter
advagg_get_css_file_contents_alter
advagg_get_js_aggregate_contents_alter
advagg_get_js_file_contents_alter
advagg_get_root_files_dir_alter
advagg_js_groups_alter
advagg_modify_css_pre_render_alter
advagg_modify_js_pre_render_alter

I tried disabling domain_conf and clientside_validation but this did not solve the problem either.

Where else should I be looking?

Thanks

mikeytown2’s picture

I'll add in these modules to the mix in order to try and repo the bug as these module implement hook_js_alter.
https://drupal.org/project/clientside_validation
https://drupal.org/project/domain
core locale

andrewhine’s picture

Thanks.

I tried disabling domain_conf and clientside_validation but this did not solve the problem either and the HTML still shows:

<script type="text/javascript" src="http://www.intrepidtravel.dev/misc/drupal.js?n1bnn2"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.js"></script>
mikeytown2’s picture

Still can not get this to fail with the new set of modules enabled on my local test box.

Have you tried the latest dev of AdvAgg? I'm testing the 2.4 but trying the latest dev might fix the issue for you. And if that still doesn't work can I get the watchdog entry under "advagg_debug" from you when you add ?advagg-debug=1 to the URL. Note that you will need the 'bypass advanced aggregation' permission in order for the debug statement to work.

andrewhine’s picture

Hi,

I've sent you a message with the contents of advagg_debug (for v2.4).

I've also tried the latest dev version but that still doesn't work.

Thanks

andrewhine’s picture

Hi

I've been debugging the code.

FYI I notice we have the attached patch applied. This redefines the drupal_sort_css_js() as drupal_sort_css_js_stable() so the line advagg.module:1073

uasort($javascript, 'drupal_sort_css_js');

Does nothing.

Changing this line to:

uasort($javascript, 'drupal_sort_css_js_stable');

Also does not fix the problem (in fact it makes it worse with more scripts complaining of Uncaught ReferenceError: jQuery is not defined).

mikeytown2’s picture

mikeytown2’s picture

Title: Order of core drupal scripts incorrect » Order of core drupal scripts incorrect when using Core patch #1388546 due to drupal_sort_css_js() being renamed
Category: Bug report » Support request
Status: Active » Fixed
FileSize
4.63 KB

I can repo this now with that core patch applied. drupal_sort_css_js() is now called drupal_sort_css_js_stable() thus the javascript doesn't get sorted due to drupal_sort_css_js() not being defined anymore. The input/output is completely different from drupal_sort_css_js(); thus the reason why doing this uasort($javascript, 'drupal_sort_css_js_stable'); made it worse is because it should have been changed to drupal_sort_css_js_stable($javascript);. If you were to disable jquery_update I would bet that the jQuery not defined error would go away as jquery_update removed the original jQuery file and thus changing the order, and with the sort not working that's how the error shows up.

I've committed this patch. It will use drupal_sort_css_js if it is available; if not available, it will then sort using advagg_drupal_sort_css_js_stable(). Reason I'm not using this as the standard way is due to the tests not passing in the original patch location and thus I'm being careful, not trying to break old behavior. Once tests pass in #1388546: Adding CSS or JS files twice changes weight I would opt to change the default to using advagg_drupal_sort_css_js_stable; thus the core patch should no longer be necessary. I've added this to the top of #2035817: Back port some code fixes for CSS optimizations

andrewhine’s picture

Hi

I can confirm advagg-2201009-11-fix-when-core-is-hacked.patch resolves the issue.

Many thanks for all your help.

Status: Fixed » Closed (fixed)

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