woocommerce/woocommerce-admin

Stop preloading large API responses into wcSettings

jsnajdr opened this issue · 0 comments

When loading the block editor page (/wp-admin/post.php) one of the largest items on the generated HTML page is a 330kB blob of wcSettings data:

<script id="wc-settings-js-before">
  var wcSettings = wcSettings || JSON.parse( decodeURIComponent( 'lot of stuff' ) )
</script>

The largest wcSettings items are two preloaded API responses in wcSettings.admin.dataEndpoints registered by wc-admin:

  • dataEndpoints[0] (182kB) is a preload of the /wc/v3 endpoint whose response is a list of metadata for 80 Woo endpoints. These data are not even used anywhere: it seems to be a bug that the woocommerce_component_settings_preload_endpoints filter has an initial value of array( '/wc/v3' ). It should be an empty array. Also note where the weird [0] key comes from.
  • dataEndpoints.countries (128kB) is a preload of the /wc-analytics/data/countries endpoint. The data are used in 4 components to populate a countries list. These components should load the data asynchronously with apiFetch or a data store instead of preloading it for everyone.