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

WordPress Trac noreply at wordpress.org
Thu May 11 19:20:13 UTC 2023


#12009: Add support for HTML 5 "async" and "defer" attributes
-------------------------------------------------+-------------------------
 Reporter:  Otto42                               |       Owner:  10upsimon
     Type:  enhancement                          |      Status:  assigned
 Priority:  high                                 |   Milestone:  6.3
Component:  Script Loader                        |     Version:  4.6
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests 2nd-        |     Focuses:
  opinion                                        |  performance
-------------------------------------------------+-------------------------

Comment (by joemcgill):

 @azaozz Thanks for laying out the background so clearly here. I'm
 generally in agreement with how you've described the current purpose of
 the Script Loader, and (other than a few nitpicks) think you’ve summarized
 the characteristics of each loading strategy well enough. That said,
 another important consideration for this proposal is that the Script
 loader also serves as the common API (along with helper functions like
 `wp_register_script` and `wp_enqueue_script`) for developers to use to
 ensure scripts are included in the HTML that WP generates.

 Given that `async` is a valid loading strategy in HTML spec, that there
 are many good use cases that developers have for using that strategy, and
 plugins are already using workarounds to make up for WP's current lack of
 direct support ([https://wpdirectory.net/search/01H01606EAF62HTP8YDT0G1Z71
 see examples]), I don't think the question should be ''if'' WordPress
 should support developers registering `async` scripts, but rather ''how''
 we should support it.

 The current approach taken in [https://github.com/WordPress/wordpress-
 develop/pull/4391#issuecomment-1538572942 PR 4391] tries to resolve
 potential load order conflicts when `async` scripts have dependencies by
 forcing them to be loaded with a `defer` or blocking strategy (whichever
 is appropriate). However, as @westonruter has pointed out, it may not make
 sense for WP to try to control loading order for `async` scripts in this
 way, given that ''by definition'' the loading order of `async` scripts is
 unpredictable and should be accounted for by developers choosing to use
 this strategy. In other words, `async` scripts absolutely can have
 dependencies, they just need to account for the `async` loading nature of
 such scripts.

 The question I'd like to get consensus on is whether we keep the current
 approach, which attempts to resolve loading order conflicts (more
 forgiving of developer mistakes) or if we should trust developers to take
 responsibility for using `async` scripts as designed and allow `async`
 scripts to have other dependencies that are `async`. Personally, I'm
 finding @westonruter's rationale for allowing developers to use `async`
 scripts as dependencies and trusting them to do so responsibly fairly
 convincing. If we can agree there, then we can address additional edge
 cases and nuances.

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


More information about the wp-trac mailing list