[wp-trac] [WordPress Trac] #12009: Add support for HTML 5 "async" and "defer" attributes
WordPress Trac
noreply at wordpress.org
Mon May 29 11:00:30 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):
Replying to [comment:114 westonruter]:
> There are other cases where async scripts occur in plugins which also
involve after scripts, but they are manually printed. For example (links
are to source code):
The consideration here, imho, is that:
1. Adding "async" attribute to script tags is not a new feature. It has
existed for many years, and many WP plugins (3000+) are already using it.
2. Estimate for the "conversion ratio" if/when support for the "async"
attribute is added to the Script Loader: My guess is that only a small
number of plugins that currently add "async" will switch to using Script
Loader. Generally only plugins that want to let third-party code (other
plugins) to remove their scripts would have a reason to switch. All the
rest will not have a reason. In these terms my estimate is that at most
about 5% of the plugins will switch to Script Loader which would be
unsatisfactory/poor conversion.
3. It seems reasonable to expect the plugins to handle cases of the rarely
used "script after" the same way plugins are expected to handle cases for
the "undefined" load order for "async" scripts. I.e. plugins that
absolutely must use a script that runs immediately after an "async" script
finishes running, and cannot do that from JS, should hande that
themselves, same as currently.
Note that there are better alternatives to run an inline script after a
script was run:
1. Can be implemented in the main script. This is by far the best option.
2. The after-script can be run on the `DOMContentLoaded` event. This event
fires after all scripts, blocking, defer, and async have been loaded and
executed.
In these terms I'd consider the Script Loader support for "after" scripts
for scripts with async and defer as **not-a-good idea**. The alternatives
are better.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/12009#comment:117>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list