-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Enqueue registered assets once #4356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enqueue registered assets once #4356
Conversation
The wp_enqueue_registered_block_scripts_and_styles callback is bound to enqueue_block_editor_assets and enqueue_block_assets. It doesn't need to, as it should be sufficient to bind it only to enqueue_block_assets. By definition, that hook fires for both front and editor.
|
I ran a performance analysis and haven't detected this PR has any impact. It is still worthwhile to do it right. For transparency, this is what I've done, so anyone can reproduce if interested.
diff --git a/.env b/.env
index 63a8169f64..789e9871c6 100644
--- a/.env
+++ b/.env
@@ -18,7 +18,7 @@ LOCAL_DIR=src
LOCAL_PHP=latest
# Whether or not to enable Xdebug.
-LOCAL_PHP_XDEBUG=false
+LOCAL_PHP_XDEBUG=true
##
# The Xdebug features to enable.
@@ -31,7 +31,7 @@ LOCAL_PHP_XDEBUG=false
#
# For a full list of accepted values, see https://xdebug.org/docs/all_settings#mode.
##
-LOCAL_PHP_XDEBUG_MODE=develop,debug
+LOCAL_PHP_XDEBUG_MODE=profile
# Whether or not to enable Memcached.
LOCAL_PHP_MEMCACHED=false
@@ -54,10 +54,10 @@ LOCAL_DB_TYPE=mysql
LOCAL_DB_VERSION=5.7
# The debug settings to add to `wp-config.php`.
-LOCAL_WP_DEBUG=true
-LOCAL_WP_DEBUG_LOG=true
-LOCAL_WP_DEBUG_DISPLAY=true
-LOCAL_SCRIPT_DEBUG=true
+LOCAL_WP_DEBUG=false
+LOCAL_WP_DEBUG_LOG=false
+LOCAL_WP_DEBUG_DISPLAY=false
+LOCAL_SCRIPT_DEBUG=false
LOCAL_WP_ENVIRONMENT_TYPE=local
# The URL to use when running e2e tests.
diff --git a/docker-compose.yml b/docker-compose.yml
index 739c65f4a8..b781c3fe94 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -39,6 +39,7 @@ services:
environment:
- LOCAL_PHP_XDEBUG=${LOCAL_PHP_XDEBUG-false}
- XDEBUG_MODE=${LOCAL_PHP_XDEBUG_MODE-develop,debug}
+ - XDEBUG_CONFIG=profiler_output_name=cachegrind.out.%R
- LOCAL_PHP_MEMCACHED=${LOCAL_PHP_MEMCACHED-false}
- PHP_FPM_UID=${PHP_FPM_UID-1000}
- PHP_FPM_GID=${PHP_FPM_GID-1000}
docker exec -it `docker ps -f name=wordpress-develop_php -q` ls -lt --full-time /tmp # List the files and inspect.
docker cp `docker ps -f name=wordpress-develop_php -q`:'/tmp/cachegrind.out._wp-admin_post_php_post=1_action=edit.gz' ~/<path-in-your-machine>
Repeat this process for
By looking at this function's implementation, I've seen that the number of times I did notice the total execution time of the request for trunk was 951ms vs 862ms in the branch. While noticeable, I couldn't track the improvement to this change. I attribute the difference to factors other than this change (variability of the profiling, etc.). |
| add_action( 'admin_enqueue_scripts', 'wp_localize_jquery_ui_datepicker', 1000 ); | ||
| add_action( 'admin_enqueue_scripts', 'wp_common_block_scripts_and_styles' ); | ||
| add_action( 'enqueue_block_assets', 'wp_enqueue_registered_block_scripts_and_styles' ); | ||
| add_action( 'enqueue_block_assets', 'enqueue_block_styles_assets', 30 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this priority still make sense? Do you know why it's there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry, I misread, I should be looking at the line above.
ellatrix
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense 👍
costdev
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @oandregal! LGTM 👍
|
Committed at https://core.trac.wordpress.org/changeset/55695 |
|
Follow-up at #4498 |
Trac ticket https://core.trac.wordpress.org/ticket/58208
Follow-up to https://core.trac.wordpress.org/ticket/45065
What
This PR removes the
wp_enqueue_registered_block_scripts_and_stylescallback from theenqueue_block_editor_assetsaction.Why
There are two actions to enqueue block assets:
enqueue_block_editor_assetsandenqueue_block_assets. The former enqueues the assets to the editor and the later enqueues them to the front-and AND the editor.Given
wp_enqueue_registered_block_scripts_and_stylesis already bound to theenqueue_block_assets(front-end & editor), it is unnecessary to bind it toenqueue_block_editor_assets(editor) as well.This was originally introduced at 76525a7 and hasn't been modified since.
How
Removes the action callback from being hooked to
enqueue_block_editor_assets.How to test
SVN commit message