[wp-trac] [WordPress Trac] #45130: Defer jQuery WordPress Admin & Customizer doesn't work properly

WordPress Trac noreply at wordpress.org
Tue Feb 12 14:23:14 UTC 2019


#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 WraithKenny):

 The convenience of jQuery's `.ready()` is that it's available early in the
 page's javascript execution (the head), such that functions can be queue'd
 (mid page) for execution on document's DOM ready event.

 Moving jQuery to the footer, or deferring the script, means that the ready
 handler is useless, since it'd not be available until `wp_footer` which is
 essentially at DOM ready anyway.

 There are many plugins and themes that expect and rely on jQuery's other
 methods to be available on the jQuery object, so even if we had a small
 shim for the ready method, it'd not solve that problem.

 Moving, or deferring, jQuery is fundamentally incompatible with WordPress.

 (Note, none of these "issues" are just with any particular version of
 jQuery, but rather they are *features* of all versions of jQuery.)

 Typically, the "best practice" advice of moving *non-critical* scripts to
 the bottom of the page is good advice that simply doesn't apply to
 *critical* scripts like jQuery in the WP ecosystem. Besides, we have http2
 now, and you can push assets in parallel (the page, and jQuery) which is a
 far better optimization than literally delaying the downloading of jQuery.

 However, if you are optimizing the theme side, for a particular client
 site, you can take a different route to this optimization, which is to use
 webpack or similar to bundle jQuery 3 directly from npm while avoiding
 plugins that rely on early jQuery.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/45130#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list