[wp-trac] [WordPress Trac] #12009: Add support for HTML 5 "async" and "defer" attributes

WordPress Trac wp-trac at lists.automattic.com
Mon Jan 9 17:14:09 UTC 2012


#12009: Add support for HTML 5 "async" and "defer" attributes
-------------------------+-----------------------------
 Reporter:  Otto42       |       Owner:  azaozz
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Future Release
Component:  JavaScript   |     Version:
 Severity:  normal       |  Resolution:
 Keywords:  needs-patch  |
-------------------------+-----------------------------

Old description:

> HTML5 supports async and defar attributes on script tags:
> http://www.w3.org/TR/html5/semantics.html#attr-script-async
>
> Basic usage of these:
>
> - "async" scripts get executed asyncronously, as soon as they're loaded.
> This lets them run without slowing down the page parsing (normally, all
> page processing stops while the javascript code is executing).
>
> - "defer" scripts get deferred from running until page processing is
> complete. Sorta like jQuery(document).ready() does, except without pre-
> definitions. Faster, in other words, since it's built into the browser.
>
> Correct usage would dictate that "libraries" like jQuery and such would
> get the async attribute, while bits of code that use the current DOM
> would get deferred. The defer bit is basically optional though, since
> most all code that exists uses something like jQuery(document).ready()
> already, when it's necessary, and so there's not a lot of benefit there.
>
> The just released Firefox 3.6 supports the async attributes, so you can
> do testing with these immediately. I've noticed a speedup on the wp-admin
> side of things by using it, but I have not measured this and cannot be
> sure I'm not imagining it. Still, it does seem like it makes the page
> appear faster.

New description:

 HTML5 supports async and defer attributes on script tags:
 http://www.w3.org/TR/html5/semantics.html#attr-script-async

 Basic usage of these:

 - "async" scripts get executed asyncronously, as soon as they're loaded.
 This lets them run without slowing down the page parsing (normally, all
 page processing stops while the javascript code is executing).

 - "defer" scripts get deferred from running until page processing is
 complete. Sorta like jQuery(document).ready() does, except without pre-
 definitions. Faster, in other words, since it's built into the browser.

 Correct usage would dictate that "libraries" like jQuery and such would
 get the async attribute, while bits of code that use the current DOM would
 get deferred. The defer bit is basically optional though, since most all
 code that exists uses something like jQuery(document).ready() already,
 when it's necessary, and so there's not a lot of benefit there.

 The just released Firefox 3.6 supports the async attributes, so you can do
 testing with these immediately. I've noticed a speedup on the wp-admin
 side of things by using it, but I have not measured this and cannot be
 sure I'm not imagining it. Still, it does seem like it makes the page
 appear faster.

--

Comment (by scribu):

 Alternatively, we could just add a filter to wp_print_scripts(), allowing
 users to add attributes when they need to.

 As always, users find weird workarounds when the API doesn't oblige. For
 example, using the clean_url filter:

 http://wordpress.stackexchange.com/a/38335/205

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/12009#comment:5>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list