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

WordPress Trac noreply at wordpress.org
Mon Mar 16 20:05:08 UTC 2020


#12009: Add support for HTML 5 "async" and "defer" attributes
---------------------------+-----------------------------
 Reporter:  Otto42         |       Owner:  azaozz
     Type:  enhancement    |      Status:  reopened
 Priority:  normal         |   Milestone:  Future Release
Component:  Script Loader  |     Version:  4.6
 Severity:  normal         |  Resolution:
 Keywords:                 |     Focuses:
---------------------------+-----------------------------

Comment (by vanaf1979):

 Be “warned” that this is my first patch, so please let me know if I’m
 doing something wrong! I'm also not sure if there is any interest left in
 resolving this topic but I thought i’d have a go.

 My patch adds two helper functions, wp_async_script and wp_defer_script
 that both take a handle or an array of handles and set is_async or
 is_defer meta values on the script objects.

 These meta values are then used in the WP_Scripts->do_item() method to add
 the appropriate attributes only when a script is not added to the footer.
 (Async and defer are assumed to be pointless in the footer!?)

 It also adds two filters, script_attr_async and script_attr_defer making
 it possible for others to change the values. I’m a bit in doubt here if
 two, or any, filters is a bit to much!? I tried to combine them but that
 makes for a pretty weird api.

 Thanks for any feedback

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/12009#comment:65>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list