-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Improve performance on Navigation view scripts #42394
Comments
Something else I just noticed: the scripts are being loaded in the Additionally, it seems that even better the scripts would be printed immediately right before the block's Some considerations would be needed when there are multiple Navigation blocks on the page, however. Ideally the same scripts wouldn't be printed more than once, so in addition to the scripts running immediately (after loading asynchronously), it should also run again at Note that this also intersects with the Interactivity API proposal, which could involve a new system for adding scripts for blocks. |
(The File block is also printing its Update: See #50113 |
Just saw there is a Trac ticket to allow a block's view scripts to load in the footer: Core-54018 |
I believe I have fixed these issues in #52536. See §Navigation Block. |
Description
Noticed while reviewing #41986
In the navigation and submenu view.js there's room for performance improvements. See for example the packages/block-library/src/navigation/view.js file:
load
event callback:load
is fired when the page and all assets (e.g. images) are fully loaded. On a page with large images, that could be a bit late. Using thedomReady
package would be a better option.querySelectorAll
should run only once.querySelectorAll
runs at any key press on the page for example at any Tab key press or any other key press, even when users type into a form field (e.g. the Comment textarea)keyup
event callback runs at any key press. I'm not sure attaching akeyup
event to the document is the best option in the first place.Similar improvements should be considered for the submenu view.js as well.
Step-by-step reproduction instructions
Screenshots, screen recording, code snippet
No response
Environment info
No response
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: