[wp-trac] [WordPress Trac] #54884: Load scripts conditionally to reduce page loading and processing time
WordPress Trac
noreply at wordpress.org
Mon Jan 24 05:48:16 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: Script Loader | Version:
Severity: normal | Resolution:
Keywords: | Focuses: javascript, performance
---------------------------+--------------------------------------
Comment (by seebeen):
Depends on the webpack setup.
Polyfills are used to provide modern JS funcionality to older browsers.
For example - https://caniuse.com/?search=es7 is the browser feature set -
you can see which minimum version of the browser supports
array.prototype.includes.
Before doing any of the conditional loading, injecting polyfills, etc. I
think it would best to agree on a minimum supported browser version. From
there we can see which polyfills we would actually need.
Additionally, conditionally loading jQuery migrate can be a potential
hurdle, because the main reason it's there is because theme and plugin
authors use deprecated jQuery APIs.
To summarize:
1) Polyfills are used for browser backward compatibility
2) jQuery migrate is used for theme / plugin compatibility with newer
versions of wordpress.
To achieve your end goal you'd need to load a detector JS file early in
the page loading process, and it cannot be an asynchronous load or a
deffered one. Script would need to block JS execution, do the detection
and shim in the polyfill / jQuery migrate. That can and will break caching
plugin, but a side-effect would be a slower and more complex page load.
To end on a high note - I think your proposal regarding wp-embed.js is
awesome. WooCommerce already has conditionals to check if a website
request is for the embed version
{{{
Constants::is_defined('IFRAME_REQUEST')
}}}
in order to prevent plugin updates when viewing embedded version of the
site. The code and the detection can be backported to WP and only load the
required embed JS / CSS when viewing the website from iframe.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/54884#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list