[wp-trac] [WordPress Trac] #54884: Load scripts conditionally to reduce page loading and processing time

WordPress Trac noreply at wordpress.org
Sun Jan 23 09:56:03 UTC 2022


#54884: Load scripts conditionally to reduce page loading and processing time
-------------------------------------+-----------------------------
 Reporter:  galbaras                 |      Owner:  (none)
     Type:  enhancement              |     Status:  new
 Priority:  normal                   |  Milestone:  Awaiting Review
Component:  General                  |    Version:
 Severity:  normal                   |   Keywords:
  Focuses:  javascript, performance  |
-------------------------------------+-----------------------------
 There are some core scripts, like `wp-polyfill` (+ `regenerator-runtime`?)
 and `jquery-migrate`, that are only needed on browsers lacking certain
 capabilities, yet these scripts are loaded on every page by default,
 whether the browser needs them or not.

 Since mobile browsers typically have the required capabilities, it's
 particularly important to avoid loading unnecessary scripts on them. This
 will improve user experience and PageSpeed scores, without any downside.

 Fortunately, browser capabilities can be detected with minimal JavaScript
 code, and only the necessary scripts added dynamically to the page using
 `appendChild()` (or maybe by manipulating script tag attributes?).

 There are also cases, such as `wp-embed`, that are only needed when there
 is an object embedded on the page, which can be detected in PHP.

 In both cases, there may be cases where the above scripts have
 dependencies that must be loaded, so both the respective front-end and
 back-end code must take dependencies into account.

 Also, browser checks should be done early and requires scripts inserted so
 as to provide their functions to subsequent code that relies on it (not
 trivial, I know, but I trust the skills of the WordPress team/community).

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/54884>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list