In #769226: Optimize JS/CSS aggregation for front-end performance and DX, the drupal_add_js() API was changed to take JS_* constants as 'group' not as part of 'weight'. 'weight' and 'group' are now separate. Attached very simple patch to implement this.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | ga_js_grouping1.patch | 1.07 KB | hass |
| ga-drupal-add-js.patch | 899 bytes | gábor hojtsy |
Comments
Comment #1
hass commentedHave you tested this? I have tried the group param in D7 beta1 or beta2 and it has not worked. The order was still incorrect. This is why I kept it as it is.
Comment #2
hass commentedTested again with D7 beta3 and
groupis broken. The code is NOT inserted before jquery.js. I guess it is a core bug, but I haven't cared about it when I found it weeks ago.Comment #3
hass commentedThis patch need to wait for #977844: Remove the 'every_page' option for CSS/JS assets: it is confusing, even damaging to be fixed.
Comment #4
effulgentsia commentedSee #769226-212: Optimize JS/CSS aggregation for front-end performance and DX.
You either need:
OR
Since this is 'inline', the net effect would be the same with either case. If this were a file, the difference would be that the former would result in being in the same aggregate file as the other JS_LIBRARY files, while the latter would result in it being in a different aggregate file.
Properly using the 'every_page' flag is a little confusing, and may need better documentation. Here's what we have so far in the PHPDoc of drupal_add_js():
And there's some additional comments in drupal_sort_css_js(). Please suggest improvements.
Comment #5
hass commentedThis is confusing.. I guess I need to read it again a few times. I need to do some testing to undestand how it works, but the every page sounds very bad as ga does not add code to every page and if nevertheless kept in aggregation it will cause JS errors as the click handler is registered, but the functions are missing. Strange logic if it works this way.
Over all I have not undstand the group stuff yet and why a weight is ignored. Major WTF
Comment #6
hass commentedComment #7
hass commented