[wp-trac] [WordPress Trac] #12009: Add support for HTML 5 "async" and "defer" attributes
WordPress Trac
noreply at wordpress.org
Mon Mar 27 21:25:44 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: | Focuses:
---------------------------+------------------------
Comment (by azaozz):
Replying to [comment:83 10upsimon]:
> Work has commenced on a solution that takes into consideration the
original essence of this Trac ticket, along with many of the suggestions
Sounds great!
> Said work that is currently underway introduces enhancements to the
Scripts API that allow loading strategies to be applied to scripts...
>
> Any early feedback is much appreciated.
There have been some changes in priorities over the last few years. For
example concatenation of scripts in wp-admin is likely to be retired soon-
ish as more and more sites are HTTP/2 or HTTP/3 enabled (also it has been
mostly broken since WP 5.0). So support for concatenation would not be a
priority and probably won't be necessary. This would simplify it a bit.
It still doesn't seem to make sense to support scripts with `async` in
Script Loader. These cannot have dependencies, cannot be used as a
dependency, and cannot have inline scripts `before` or `after`. Ideally
plugins and themes that want to use them would output the script tags
themselves on one of the `<head>` actions. Alternatively Script Loader may
have a separate queue for them just so `wp_enqueue_script()` can be used,
but not sure how much sense that would make.
Seems scripts with `defer` can have dependencies that are "blocking" (i.e.
without `defer`). They can also have inline scripts that load `before` but
cannot have `after` scripts.
Also seems that scripts with `defer` can be used as dependencies, but the
dependent script will have to have `defer` too. This seems to make it
possible to have a mix of `defer` and "blocking" scripts as dependencies
which may be a bit messy.
To prevent problems a "blocking" script should not be able to use a
`defer` script as a dependency. In theory that may be possible if the
`defer` attribute is removed, but that seems to additionally complicate
things and may bring edge cases. Also attempting to add an `after` script
to a script with `defer` should not be possible. Thinking these two should
probably throw a `doing_it_wrong`.
Another big development is the possibility to use JavaScript modules, see:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules.
This is a significant change in how JS is handled by the browsers that
brings many enhancements and new features like deferred by default,
loading of modules when needed, etc.
It seems that JavaScript modules would be pretty nice for the block
editor/Gutenberg, and are outside the scope of Script Loader.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/12009#comment:86>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list