[wp-trac] [WordPress Trac] #12009: Add support for HTML 5 "async" and "defer" attributes
WordPress Trac
noreply at wordpress.org
Tue Mar 6 01:06:12 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 westonruter):
Replying to [comment:46 azaozz]:
> Currently there are few tickets that touch on some parts of
updating/refactoring script-loader. IMHO best would be to combine them and
really refactor it. Implement HTTP/2 + `defer`, output all in the head,
retire load-scripts.php, etc. etc. Ideally this should be done before
Gutenberg lands in core.
Retiring `load-scripts.php` I think can also/rather be accomplished via
service workers: #36995.
> The `async` attribute cannot be used in script-loader because the script
doesn't follow execution order. If you are adding a stand-alone script
that has no dependencies and other scripts don't depend on it, there is no
point adding it to script loader at all.
It would make sense to me that if you register a script with an `async`
flag ''and'' a non-empty `deps` that this should result in a
`_doing_it_wrong()`.
It makes sense to me to use the WP dependency system even if there are no
dependencies because it provides a standard programatic interface for
registering and outputting scripts. Core or a plugin could register an
`async` script and then it or other plugins could just simply enqueue it
and be done with it, as is standard in WP. A plugin could check to see if
a script is already registered and prevent registering and enqueueing
their own if it already exists. Also no worrying about adding an action to
print a manually-crafted `script` tag. No (less) worrying about duplicated
scripts being output.
> Currently there are few tickets that touch on some parts of
updating/refactoring script-loader. IMHO best would be to combine them and
really refactor it. Implement HTTP/2 + `defer`, output all in the head,
retire load-scripts.php, etc. etc. Ideally this should be done before
Gutenberg lands in core.
Just to be clear, I'm talking about WP script dependencies generally not
`load-scripts.php` specifically. I think there is good value in adding
`async` and `defer` support to the existing `WP_Scripts` system so that we
can take advantage of them now. Since you noted that less than 25% of the
Web is on HTTP/2, I don't think we should let it be the blocker for us to
encourage best practices now for script loading for themes and plugins via
`async` and `defer`. HTTP/2 definitely won't be available before
Gutenberg.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/12009#comment:47>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list