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.
We are able to move JavaScript to the footer on all pages of our site except the Calendar views pages that use calendar_overlap.js: http://cgit.drupalcode.org/calendar/tree/js/calendar_overlap.js?id=1c6e935
This script causes the views to render as broken. As soon as we disable AdvAgg's move JS to the footer, the page works as expected.
What about adding a textarea immediately below "Move JS to the footer" that is "Disable 'move JS to the footer' on specific pages"? This would be similar to the textareas already in place under "Inline CSS/JS on Specific Pages".
Comment | File | Size | Author |
---|---|---|---|
#23 | advagg-2632512-23-alter-js-defer-async.patch | 1.36 KB | mikeytown2 |
#23 | advagg-2632512-22-alter-js-footer-setting.patch | 2.14 KB | mikeytown2 |
#17 | allow_disabling_of-2632512-17.patch | 2.5 KB | NickDickinsonWilde |
#8 | advagg_move_js_to_footer_disabled.png | 60.44 KB | ron_s |
#8 | advagg_move_js_to_footer_enabled.png | 25.63 KB | ron_s |
Comments
Comment #2
ron_s CreditAttribution: ron_s commentedLooking more closely at the code, another idea would be to make the values in
$all_in_footer_list
(or something similar to it) accessible through a textarea. This would allow developers to enter a path such as "/sites/all/modules/calendar/js/calendar_overlap.js" to not be moved to the footer.Comment #3
mikeytown2 CreditAttribution: mikeytown2 commentedThis should do it. What it's saying is if the calendar_overlap.js file is included then do not put these files in the footer as well.
Comment #4
ron_s CreditAttribution: ron_s commentedThanks for the alter code, certainly makes sense to handle it that way. We will give it a try.
Was also asking if it might be worthwhile to provide an option in the user interface for developers. Possibly leverage the "per file settings" code used on the JS compression page, and allow devs to select which JS files will cause core files to not be put in the footer?
Comment #5
mikeytown2 CreditAttribution: mikeytown2 commentedFor how simple it seems making a decent interface for this would take a lot of effort. So in that front I'm open to patches, I will not be the one creating it.
Comment #6
ron_s CreditAttribution: ron_s commentedThank you, I was not suggesting it is a simple task. I was merely offering the 'per file settings' functionality as a representative example, and asking if you felt it would be worthwhile functionality to add. You have a much better sense of what features might be valued by those who use the module than I do.
Thanks for the feedback and we'll give the hook a try shortly.
Comment #7
ron_s CreditAttribution: ron_s commentedWe have tested the hook in #3 and looks like it does the job. Thank you very much!
Do you think it would it be of value to add the hook to
advagg.api.php
with an example for others?Comment #8
ron_s CreditAttribution: ron_s commentedOn closer examination, I think I spoke too soon. Looks like the cache was not fully cleared when I last checked, and the suggested hook doesn't impact the result. I'm only able to see calendar days if I disable moving JavaScript to the footer.
See attached images.
Comment #9
ron_s CreditAttribution: ron_s commentedWas looking at the
calendar-day-overlap.tpl.php
template, and it has inline jQuery to hide the container while the page is rendering. This seems to be the issue, since#single-day-container
is being loaded with content, but has CSS of "visibility:hidden".What's the proper way to handle inline JS from other modules with AdvAgg?
http://cgit.drupalcode.org/calendar/tree/theme/calendar-day-overlap.tpl....
http://cgit.drupalcode.org/calendar/tree/theme/calendar-day-overlap.tpl....
Comment #10
mikeytown2 CreditAttribution: mikeytown2 commentedAdvAgg does it's best in terms of handling js that has been added without drupal_add_js(). In regards to js that has been added to a tpl file that's tricky. If the contents of that tpl file are available inside of template_process_html() then advagg_mod should be able to wrap the inline js by enabling the "Put a wrapper around inline JS if it was added in the content section incorrectly" checkbox; you can play around with "Use XPath instead of regex when searching for inline scripts" to see if XPath does a better job in comparison to regex.
Comment #11
ron_s CreditAttribution: ron_s commentedThanks for the suggestions, still got the same results.
Would you recommend the best way to fix this would be by patching Calendar?
Comment #12
mikeytown2 CreditAttribution: mikeytown2 commentedWith that enabled do the script tags get a wrapper in the html output?
Comment #13
ron_s CreditAttribution: ron_s commentedIt seems as though they do. This is the code at the start of
#single-day-container
:And this is the code immediately after the "
single-day-footer
" at the end of the content section:Comment #14
mikeytown2 CreditAttribution: mikeytown2 commentedAt this point yes it seems like calendar's js code is not defer safe. I've had similar issues with just about every map's js code as well so it's not unheard of.
Comment #15
ron_s CreditAttribution: ron_s commentedAre there issues or patches for maps you can point me to so I can create a Calendar module patch? Thanks.
Comment #16
mikeytown2 CreditAttribution: mikeytown2 commentedUnfortunately no. At this point creating a solution based off of #3 seems like the best option unless you can make the js "async safe", which would take a lot of effort to do most likely. For maps I use a solution similar to #3
Comment #17
NickDickinsonWildeHere's an alternate solution...
patch attached that adds a $footer_page_skip_list to advagg_mod_js_move_to_footer().
Also adds a field to the advagg_mod's admin page to add pages to the list.
So @ron_s: if you tell us the path to that calender, assuming @mikeytown2 is okay with the idea/my implementation of it, that could also be added to the patch and then the next version of advagg would "just work" out of the box with that calendar module.
Comment #18
NickDickinsonWildeComment #19
ron_s CreditAttribution: ron_s commentedNick, thanks for the patch. I don't have time at the moment to review, but most likely I will next week.
Regarding "just working" out of the box with the Calendar module, it would be the calendar/week and calendar/day paths. However, I'm not sure if it's best to add this by default, or provide some guidance in the module notes.
If the Calendar module owners update the JS in the future, there could be a situation where the paths don't need to be included. Also, if a Drupal developer chooses not to use the default Overlap functionality, we would be skipping AdvAgg's capabilities on a page where it could be enabled. Another potential issue is if a developer changes the path of their calendar views, and doesn't realize AdvAgg has hard-coded calendar paths.
Comment #20
mikeytown2 CreditAttribution: mikeytown2 commentedI'm hesitant on doing this per page; being able to target the js file that doesn't work seems like a more sustainable option.
Comment #23
mikeytown2 CreditAttribution: mikeytown2 commentedChanged the hook from #3 so it has access to the $js list and it can change the $move_js_to_footer variable. This patch has been committed and with it you should be able to do what you want by using the hook like this
Also committed a patch that allows for the async and defer settings to be changed as well.
Comment #24
ron_s CreditAttribution: ron_s commented@mikeytown, thanks for these patches. I finally had a chance to test and was able to get it to work successfully.
I was setting both the
$move_js_to_footer
and$defer_setting
values in the user interface, so I had to add$lists[8] = 0;
to the function too. Worked just as I would expect.