apiFetch preloading middleware ships 1MB+ of redundant REST data #27370
Labels
Core REST API Task
Task for Core REST API efforts
Needs Dev
Ready for, and needs developer efforts
[Type] Performance
Related to performance efforts
Describe the bug
The
apiFetch
preloading middleware can easily ship more than 1MB of redundant data on the initial load. Only few kilobytes or even bytes out of that are ever really used by the app.To reproduce
Steps to reproduce the behavior:
/wp-admin/post.php?post=921&action=edit
wp.apiFetch.createPreloadingMiddleware
Expected behavior
The preloaded data contain more or less only the information that the editor really uses, and don't have a 100x or even 1000x overhead.
Actual behavior
On a testing site with Jetpack and WooCommerce, two popular plugins that register quite a few REST routes, I see that:
The
post.php?post=id&action=edit
response is 1.7MB (174kB compressed) of HTML and inline CSS and JS.The
wp.apiFetch.createPreloadingMiddleware
call has an argument that's 930kB big.The preload data for the
/
path contain a few bytes of information that the editor may really want (site name, description, URL, time zone) and then, in thebody.routes
field, a complete meta-description of all registered REST routes.The preload data for the
OPTIONS /wp/v2/media
request are 17kB of mostlybody.endpoints
data with detailed descriptions of the supportedGET
andPOST
request params, while the relevant information is just one line:that says whether the current user is allowed to
POST
to/wp/v2/media
, i.e., has upload permissions. See also #4155 that added theOPTIONS /wp/v2/media
preload specifically and #12378 where @noisysocks introduced a general-purposecanUser
selector that usesOPTIONS
requests and theirAllow
response header to detect capabilities.The signal-to-noise ratio of these
OPTIONS
responses is very low, on the "20 bytes out of 20 kilobytes" scale.Editor version (please complete the following information):
The text was updated successfully, but these errors were encountered: