Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Howdy,
This is an awesome module! Thanks to this module, I have successfully improved page load times. Thank you for creating it!
I have a couple of pages where I need to include some JS both in the head and in the body sections of the page, and for this pages, I need the JS to stay in its original location.
In order to achieve the above, is there any way to magically disable "Optimize JavaScript Ordering" and "Adjust javascript location and execution" for specific pages (say, for example, by path)?
Please advise.
Jorge
Comments
Comment #2
mikeytown2 CreditAttribution: mikeytown2 commentedCustom code would be the way to do exactly what you're describing. My preference is to use the arg() function for finding the current Drupal path.
Another alternative is to implement hook_advagg_mod_get_lists_alter() if it's a specific file that you want to target.
Examples of this hook
AdvAgg will already not move some JS to the footer if `misc/ajax.js` is being used. This code looks like this
AdvAgg will also not move js to the footer for these files
And if you have the google_admanager module installed it will not move the following inline code to the footer as well
Comment #3
ilfelice CreditAttribution: ilfelice commentedHi mikeytown2!
Thank you so much for the prompt reply.
Not being much of a programmer, I have to ask: the arg() function sample code above, would that go in the theme's template.php file, or is it supposed to go into a custom module?
Jorge
Comment #4
ilfelice CreditAttribution: ilfelice commentedTo be more specific, assuming the code goes into template.php, would something like this work?
Jorge
Comment #5
mikeytown2 CreditAttribution: mikeytown2 commentedtemplate.php with the theme_name as hook will work.
I don't know if the path inquiry is an alias or an internal drupal path so I've covered both cases below.
Comment #6
mikeytown2 CreditAttribution: mikeytown2 commentedAssuming #5 did the trick. Marking this issue as fixed.
Comment #7
ilfelice CreditAttribution: ilfelice commentedHello mikeytown2,
Apologies for the delay in responding. ;)
I added the above code in #5 to my theme template, making sure that I changed
portion in the name of the function to the theme name.
I then did a "drush cc" to flush all caches, and restarted apache to clear opcache.
After all this, I loaded a couple of pages under the inquiry path.
Unfortunately, the JS reordering and optimization was still happening.
The paths are all aliases, such as those below:
https://demo.com/inquiry
https://demo.com/inquiry/general
https://demo.com/inquiry/electronics
https://demo.com/inquiry/heatsink
https://demo.com/inquiry/medical
https://demo.com/inquiry/construction
I wonder if there is anything else that I need to do... Any further suggestions?
Jorge
Comment #8
mikeytown2 CreditAttribution: mikeytown2 commentedNeed to see if the hook is working and that the correct page is targeted. This will display a message.
Comment #9
ilfelice CreditAttribution: ilfelice commentedmikeytown2,
I tried this code in #8 on a separate box, and no message was displayed.
Just in case, i switched themes (to Bartik), of course adding the code to template.php, but to no avail.
I must be doing something wrong, but just can't figure out what it is is...
Any suggestions?
Comment #10
mikeytown2 CreditAttribution: mikeytown2 commentedInstead of hook_page_build try hook_page_alter
Comment #11
ilfelice CreditAttribution: ilfelice commentedmikeytown2,
> Instead of hook_page_build try hook_page_alter
Yay! That did the trick!
I did have to remove the backslash after inquiry in the if line, so that the exclusion would happen in the /inquiry path as well.
So, here is the code I used (in case it can be useful to others):
Thank again mikeytown2!
Jorge
Comment #12
mikeytown2 CreditAttribution: mikeytown2 commentedAwesome, glad this worked out for you!