[wp-trac] [WordPress Trac] #15381: Rework WP_Scripts to support named groups
WordPress Trac
wp-trac at lists.automattic.com
Wed Dec 1 16:53:25 UTC 2010
#15381: Rework WP_Scripts to support named groups
--------------------------+-------------------------------------------------
Reporter: westi | Owner: westi
Type: defect (bug) | Status: new
Priority: normal | Milestone: Future Release
Component: JavaScript | Version:
Severity: normal | Keywords: 3.2-early
--------------------------+-------------------------------------------------
Comment(by andy):
Replying to [comment:3 westi]:
> To think about: http://headjs.com/
I spent an evening hacking together a plugin that extends WP_Scripts to
use head.js rather than individual script tags. It worked in the sense
that it caused the page to load without blocking for the scripts. However,
it broke several of the most basic scripted function such as the
collapsing admin menus.
We commonly use inline scripts with the assumption that dependencies are
already loaded. When loading scripts with head.js, you can't assume this.
The fix is simple: wrap the script in a head.js call that delays execution
until the dependency is fulfilled. You can still use inline scripts; you
just have to take this little extra step (for which we could build helpers
into WP_Scripts/WP_Dependencies).
{{{
<script>
// call a function assuming jQuery Tools is loaded
jQuery(".tip").tooltip();
</script>
}}}
{{{
<script>
// call a function immediately after jQuery Tools is loaded
head.ready("tools", function() {
$(".tip").tooltip();
});
</script>
}}}
It is possible to use script concatenation with head.js but I don't think
it has facilities for one script to fulfill multiple dependencies. I have
created an [https://github.com/headjs/headjs/issues/issue/11 issue] on the
head.js project on GitHub.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/15381#comment:4>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list