#9620 closed defect (bug) (fixed)
problems with the new footer script loader
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 2.8 | Priority: | normal |
| Severity: | major | Version: | 2.8 |
| Component: | JavaScript | Keywords: | has-patch dev-feedback |
| Focuses: | Cc: |
Description
I ran into this while trying to figure out why one of my admin js wasn't working on the widgets screen. I was running the following:
wp_enqueue_script('jquery-livequery', $plugin_path . 'jquery.livequery.js', array('jquery'), '1.1');
wp_enqueue_script('jquery-ui-droppable', $plugin_path . 'ui.droppable.js', array('jquery-ui-draggable'), '1.7.1');
wp_enqueue_script('nav-menus', $plugin_path . 'admin.js', array('jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-livequery'), '20090422');
I eventually tossed everything into the footer and things worked fine:
wp_enqueue_script('jquery-livequery', $plugin_path . 'jquery.livequery.js', array('jquery'), '1.1', true );
wp_enqueue_script('jquery-ui-droppable', $plugin_path . 'ui.droppable.js', array('jquery-ui-draggable'), '1.7.1', true);
wp_enqueue_script('nav-menus', $plugin_path . 'admin.js', array('jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-livequery'), '20090422', true);
... but I still believe it's a genuine bug.
My script depends on draggable and sortable, both of which land in the footer according to WP. Mine would seek to initialize before the footer scripts, and would miserably fail as a result.
To maintain backwards compatibility, footer scripts that are depends of scripts that are required in the header should be treated as header scripts.
Attachments (2)
Change History (8)
#3
@
17 years ago
This is handled in the WP_Dependency class and seems to work properly here. Perhaps it's failing somewhere else. Some more info would help.
#6
in reply to:
↑ 4
@
17 years ago
Replying to Denis-de-Bernardy:
the attached plugin will hopefully convince you.
It was moving only the first level of dependencies so in custom_scr->ui.draggable->ui.core->jquery only the ui.draggable would have been moved from the footer to the head.
attached is a potential fix, which works. but I just thought of a better way.
specifically, instead of being overriding when registered, they should be overridden when enqueued.