[wp-trac] [WordPress Trac] #12009: Add support for HTML 5 "async" and "defer" attributes
WordPress Trac
noreply at wordpress.org
Fri Feb 17 17:06:49 UTC 2017
#12009: Add support for HTML 5 "async" and "defer" attributes
---------------------------+------------------------------
Reporter: Otto42 | Owner: azaozz
Type: enhancement | Status: reopened
Priority: normal | Milestone: Awaiting Review
Component: Script Loader | Version: 4.6
Severity: normal | Resolution:
Keywords: | Focuses:
---------------------------+------------------------------
Comment (by seancjones):
I think this is an important issue to resolve. As of now, Google Page
Speed Insights failing for a lot of WordPress installs can almost
exclusively be blamed on render-blocking JavaScript. Fixing that increases
speed by wide margins.
Plugin developers should have a way of deferring page loads. There are
clear pitfalls to avoid - like people's websites breaking.
I'm going to play devil's advocate and argue why a filter might be better.
A filter allows a user with a code sample to defer scripts, or remove
scripts if they appear to break their current setup. Plugin developers can
send an array of script handles to defer via a plugin, rather than rewrite
their code with a new parameter.
If a user wanted to disable all deferring:
{{{
add_filter ( 'wp_defer_scripts', function($wp_defer) {
return array();
}, 900, 2 );
add_filter ( 'wp_async_scripts', function($wp_async) {
return array();
}, 900, 2 );
}}}
For someone to enable all hooks:
{{{
add_filter ( 'wp_async_scripts', function($wp_async) {
global $wp_scripts;
return $wp_scripts->queue;
} );
}}}
This would also make it far easier for plugin developers to patch their
plugins.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/12009#comment:33>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list