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

WordPress Trac noreply at wordpress.org
Tue May 9 22:36:55 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 azaozz):

 > 1. One point is to potentially fall back to another strategy for an
 `async` script if e.g. a blocking script depends on it.

 Thinking the decision here is about what has the higher priority:
 - A script is intended to be loaded as `async`.
 - Some plugin or theme decides to use a third-party `async` script as a
 dependency.

 Imho the forst is higher priority than the second because generally
 `async` scripts are designed to be stand-alone and/or non-dependent on
 (old-style) loading order. Hence excluding them from script-loader makes
 most sense.

 (Also keep in mind that it is possible to write JS that does not depend on
 script loading order. Such JS code can use any script as a dependency,
 even scripts that are (dynamically) loaded a lot later with AJAX or things
 like `document.write()`).

 > my take based on our conversation earlier is that we should still allow
 for an `async` script to fall back to blocking if needed...
 > The `async` scripts basically don't care ''when'' they load

 Not sure if that's a good idea. As far as I see scripts that are loaded as
 `async` are "special" and may implement things that should not block the
 page loading.

 > For the second point, I now agree that for scripts added with `async` we
 can allow dependencies (as already hinted by my example to explain the
 first point). We still have to clearly explain the considerations for
 doing so

 Again, ideally the script-loader will not support scripts with `async`.
 Doesn't seem to make sense to handle them there, even less if the `async`
 is automatically removed.

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


More information about the wp-trac mailing list