[wp-trac] [WordPress Trac] #48654: Consider a solution/endpoint to lazy-load scripts and styles
WordPress Trac
noreply at wordpress.org
Fri Nov 15 11:42:51 UTC 2019
#48654: Consider a solution/endpoint to lazy-load scripts and styles
----------------------------------+-----------------------------
Reporter: youknowriad | Owner: (none)
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version:
Severity: normal | Keywords:
Focuses: javascript, rest-api |
----------------------------------+-----------------------------
As we move towards more JavaScript-heavy UIs, the need to lazy-load assets
for performance reasons is increasing.
The Gutenberg plugin has also an experimental feature allowing users to
install blocks available in the block directory without leaving the editor
or refreshing the page.
In all these situations we need to load assets (JavaScript scripts and
stylesheets) from the server. The only thing the client knows is the
"handle" of these scripts and styles. It doesn't know the dependencies of
these scripts and styles which need to be loaded as well.
So, the requirements here are:
- Given a script or style handle name, retrieve its dependencies.
(Possibly an endpoint)
- Load these dependencies in the client without duplication (possibly a
task that will be tackled in a separate ticket)
Ideally, this endpoint would work for any script and style handle but
historically WordPress users may have attached sensible data to their
scripts (by calling localize_script or add_inline_script). A solution
here should address that issue
Potential solutions:
- **whitelist** have a flag similar to show_in_rest saying whether the
script is whitelisted or not. This solution risk excluding way too much
scripts and styles creating bad user experiences (no lazy load possible,
no inline block installs...)
- **blacklist** Potentially find a way to detect sensible scripts and
styles with rules, for example by saying that all localized scripts are
blacklisted by default unless authorized using a flag.
- Other solutions I didn't think of :)
No matter the solution, if we're not able to load all the dependencies,
the client should be notified (in the endpoint response maybe) in order to
take the proper action in that case.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/48654>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list