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

WordPress Trac noreply at wordpress.org
Tue Mar 6 12:10:17 UTC 2018


#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 azaozz):

 Replying to [comment:48 mor10]:
 > For clarity: We should not blanket `defer` all scripts. A decision as to
 what approach is best (default, `async`, or `defer`) needs to be done on a
 script-by-script basis to optimize performance.

 I don't think so. Mixing the "old" and "new" way of adding scripts will
 result in a big mess. A typical user case:
 - I enqueue myscript.js to load the old fashioned way in the footer.
 - It depends on `jquery-ui-dialog` which depends on most of jQuery UI.
 - However another plugin decides it wants to load `jquery-ui-position`
 with `defer`. Deferred scripts will be executed after the footer scripts
 which breaks the execution order for myscript.js and possibly some of the
 other dependencies.

 To prevent this from happening we will have to actively '''ban''' use of
 `defer` for all default scripts in core (not even sure we can do that
 easily).

 In that case, what would be the benefits of a plugin adding its own script
 with `defer`?
 - All core dependencies will still have to be loaded in the footer.
 - HTTP2 won't work on 75% of the sites, so it will end up slowing down 3/4
 of them.

 Where is the optimization here? Isn't that rather saying: "We added
 support for `defer` but it will not work the way it should".

 I'm going to repeat myself: if we want to make this better we should "go
 for broke", refactor script-loader and fully implement loading of scripts
 as it should be in 2018. No point of doing little things that don't make
 much of a difference :)

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


More information about the wp-trac mailing list