[wp-trac] [WordPress Trac] #45130: Defer jQuery WordPress Admin & Customizer doesn't work properly
WordPress Trac
noreply at wordpress.org
Fri Oct 26 02:00:04 UTC 2018
#45130: Defer jQuery WordPress Admin & Customizer doesn't work properly
----------------------------+------------------------------
Reporter: remzicavdar | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Administration | Version:
Severity: normal | Resolution:
Keywords: needs-patch | Focuses: javascript
----------------------------+------------------------------
Comment (by dlh):
Regarding updating jQuery, it might be better to bring your suggestions to
the discussion at #37110, where more contributors are likely to see it. (I
was referring to backwards-compatibility just with respect to deferring
jQuery — sorry for the confusion.)
The checks for `is_admin()` or `is_customize_preview()` could go at the
beginning of your `script_loader_tag` filter:
{{{#!php
<?php
function add_defer_attribute( $tag, $handle ) {
if ( is_admin() || is_customize_preview() ) {
return $tag;
}
// add script handles to the array below
$scripts_to_defer = array(
'jquery',
'jquery-migrate',
'bootstrap-bundle-js'
);
foreach ( $scripts_to_defer as $defer_script ) {
if ( $defer_script === $handle ) {
return str_replace( ' src', ' defer="defer" src',
$tag );
}
}
return $tag;
}
add_filter( 'script_loader_tag', 'add_defer_attribute', 10, 2 );
}}}
However, Trac isn't meant for support, so you might want to ask additional
questions about specific implementations at the
[https://wordpress.org/support/ support forums] or
[https://wordpress.stackexchange.com/ WordPress Development Stack
Exchange].
--
Ticket URL: <https://core.trac.wordpress.org/ticket/45130#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list